@@ -152,26 +152,17 @@ public class HoodieTestDataGenerator implements AutoCloseable {
152152 + "{\" name\" :\" ts_micros\" ,\" type\" :{\" type\" :\" long\" ,\" logicalType\" :\" timestamp-micros\" }},"
153153 + "{\" name\" :\" local_ts_millis\" ,\" type\" :{\" type\" :\" long\" ,\" logicalType\" :\" local-timestamp-millis\" }},"
154154 + "{\" name\" :\" local_ts_micros\" ,\" type\" :{\" type\" :\" long\" ,\" logicalType\" :\" local-timestamp-micros\" }},"
155- + "{\" name\" :\" event_date\" ,\" type\" :{\" type\" :\" int\" ,\" logicalType\" :\" date\" }},"
156- + "{\" name\" :\" dec_fixed_small\" ,\" type\" :{\" type\" :\" fixed\" ,\" name\" :\" decFixedSmall\" ,\" size\" :3,\" logicalType\" :\" decimal\" ,\" precision\" :5,\" scale\" :2}},"
157- + "{\" name\" :\" dec_fixed_large\" ,\" type\" :{\" type\" :\" fixed\" ,\" name\" :\" decFixedLarge\" ,\" size\" :8,\" logicalType\" :\" decimal\" ,\" precision\" :18,\" scale\" :9}}," ;
158-
155+ + "{\" name\" :\" event_date\" ,\" type\" :{\" type\" :\" int\" ,\" logicalType\" :\" date\" }}," ;
159156 public static final String EXTENDED_LOGICAL_TYPES_SCHEMA = "{\" name\" :\" ts_millis\" ,\" type\" :{\" type\" :\" long\" ,\" logicalType\" :\" timestamp-millis\" }},"
160157 + "{\" name\" :\" ts_micros\" ,\" type\" :{\" type\" :\" long\" ,\" logicalType\" :\" timestamp-micros\" }},"
161158 + "{\" name\" :\" local_ts_millis\" ,\" type\" :{\" type\" :\" long\" ,\" logicalType\" :\" local-timestamp-millis\" }},"
162159 + "{\" name\" :\" local_ts_micros\" ,\" type\" :{\" type\" :\" long\" ,\" logicalType\" :\" local-timestamp-micros\" }},"
163- + "{\" name\" :\" event_date\" ,\" type\" :{\" type\" :\" int\" ,\" logicalType\" :\" date\" }},"
164- + "{\" name\" :\" dec_plain_large\" ,\" type\" :{\" type\" :\" bytes\" ,\" logicalType\" :\" decimal\" ,\" precision\" :20,\" scale\" :10}},"
165- + "{\" name\" :\" dec_fixed_small\" ,\" type\" :{\" type\" :\" fixed\" ,\" name\" :\" decFixedSmall\" ,\" size\" :3,\" logicalType\" :\" decimal\" ,\" precision\" :5,\" scale\" :2}},"
166- + "{\" name\" :\" dec_fixed_large\" ,\" type\" :{\" type\" :\" fixed\" ,\" name\" :\" decFixedLarge\" ,\" size\" :8,\" logicalType\" :\" decimal\" ,\" precision\" :18,\" scale\" :9}}," ;
160+ + "{\" name\" :\" event_date\" ,\" type\" :{\" type\" :\" int\" ,\" logicalType\" :\" date\" }}," ;
167161
168162 // LTS = Local Timestamp
169163 public static final String EXTENDED_LOGICAL_TYPES_SCHEMA_NO_LTS = "{\" name\" :\" ts_millis\" ,\" type\" :{\" type\" :\" long\" ,\" logicalType\" :\" timestamp-millis\" }},"
170164 + "{\" name\" :\" ts_micros\" ,\" type\" :{\" type\" :\" long\" ,\" logicalType\" :\" timestamp-micros\" }},"
171- + "{\" name\" :\" event_date\" ,\" type\" :{\" type\" :\" int\" ,\" logicalType\" :\" date\" }},"
172- + "{\" name\" :\" dec_plain_large\" ,\" type\" :{\" type\" :\" bytes\" ,\" logicalType\" :\" decimal\" ,\" precision\" :20,\" scale\" :10}},"
173- + "{\" name\" :\" dec_fixed_small\" ,\" type\" :{\" type\" :\" fixed\" ,\" name\" :\" decFixedSmall\" ,\" size\" :3,\" logicalType\" :\" decimal\" ,\" precision\" :5,\" scale\" :2}},"
174- + "{\" name\" :\" dec_fixed_large\" ,\" type\" :{\" type\" :\" fixed\" ,\" name\" :\" decFixedLarge\" ,\" size\" :8,\" logicalType\" :\" decimal\" ,\" precision\" :18,\" scale\" :9}}," ;
165+ + "{\" name\" :\" event_date\" ,\" type\" :{\" type\" :\" int\" ,\" logicalType\" :\" date\" }}," ;
175166
176167 public static final String TRIP_EXAMPLE_SCHEMA =
177168 TRIP_SCHEMA_PREFIX + EXTRA_TYPE_SCHEMA + MAP_TYPE_SCHEMA + FARE_NESTED_SCHEMA + TIP_NESTED_SCHEMA + TRIP_SCHEMA_SUFFIX ;
@@ -431,9 +422,17 @@ public RawTripTestPayload generatePayloadForShortTripSchema(HoodieKey key, Strin
431422 * Generates a new avro record of the above schema format for a delete.
432423 */
433424 private RawTripTestPayload generateRandomDeleteValue (HoodieKey key , String instantTime ) throws IOException {
425+ return generateRandomDeleteValue (key , instantTime , TRIP_EXAMPLE_SCHEMA );
426+ }
427+
428+ private RawTripTestPayload generateRandomDeleteValue (HoodieKey key , String instantTime , String schemaStr ) throws IOException {
434429 GenericRecord rec = generateGenericRecord (key .getRecordKey (), key .getPartitionPath (), "rider-" + instantTime , "driver-" + instantTime , 0 ,
435430 true , false );
436- return new RawTripTestPayload (Option .of (rec .toString ()), key .getRecordKey (), key .getPartitionPath (), TRIP_EXAMPLE_SCHEMA , true , 0L );
431+ return new RawTripTestPayload (Option .of (rec .toString ()), key .getRecordKey (), key .getPartitionPath (), schemaStr , true , 0L );
432+ }
433+
434+ private RawTripTestPayload generateRandomDeleteValuePerSchema (HoodieKey key , String instantTime , String schemaStr ) throws IOException {
435+ return generateRandomValueAsPerSchema (schemaStr , key , instantTime , false , true , 0L );
437436 }
438437
439438 /**
@@ -556,8 +555,7 @@ private void generateTripSuffixValues(GenericRecord rec, boolean isDeleteRecord)
556555 * Generate record conforming to TRIP_EXAMPLE_SCHEMA or TRIP_FLATTENED_SCHEMA if isFlattened is true
557556 */
558557 public GenericRecord generateGenericRecord (String rowKey , String partitionPath , String riderName , String driverName ,
559- long timestamp , boolean isDeleteRecord ,
560- boolean isFlattened ) {
558+ long timestamp , boolean isDeleteRecord , boolean isFlattened ) {
561559 GenericRecord rec = new GenericData .Record (isFlattened ? FLATTENED_AVRO_SCHEMA : AVRO_SCHEMA );
562560 generateTripPrefixValues (rec , rowKey , partitionPath , riderName , driverName , timestamp );
563561 if (isFlattened ) {
@@ -664,38 +662,6 @@ public RawTripTestPayload generateRecordForTripLogicalTypesSchema(HoodieKey key,
664662 // event_date
665663 int eventDateBase = (int ) dateThreshold .toEpochDay ();
666664 rec .put ("event_date" , above ? eventDateBase + 1 : eventDateBase - 1 );
667-
668-
669- // -------------------
670- // Decimal thresholds
671- // -------------------
672- BigDecimal decPlainLargeThreshold = new BigDecimal ("1234567890.0987654321" ); // precision=20, scale=10
673-
674- BigDecimal decFixedSmallThreshold = new BigDecimal ("543.21" ); // precision=5, scale=2
675- BigDecimal decFixedLargeThreshold = new BigDecimal ("987654321.123456789" ); // precision=18, scale=9
676-
677- // Increment for just-above/below threshold = smallest possible unit for that scale
678- BigDecimal incSmallScale2 = new BigDecimal ("0.01" );
679- BigDecimal incLargeScale9 = new BigDecimal ("0.000000001" );
680- BigDecimal incLargeScale10 = new BigDecimal ("0.0000000001" );
681-
682- // Assign thresholded decimals
683- if (!v6 ) {
684- rec .put ("dec_plain_large" , ByteBuffer .wrap ((above
685- ? decPlainLargeThreshold .add (incLargeScale10 )
686- : decPlainLargeThreshold .subtract (incLargeScale10 )).unscaledValue ().toByteArray ()));
687- }
688-
689- Conversions .DecimalConversion decimalConversions = new Conversions .DecimalConversion ();
690- Schema decFixedSmallSchema = AVRO_TRIP_LOGICAL_TYPES_SCHEMA .getField ("dec_fixed_small" ).schema ();
691- rec .put ("dec_fixed_small" , decimalConversions .toFixed (above
692- ? decFixedSmallThreshold .add (incSmallScale2 )
693- : decFixedSmallThreshold .subtract (incSmallScale2 ), decFixedSmallSchema , LogicalTypes .decimal (5 , 2 )));
694-
695- Schema decFixedLargeSchema = AVRO_TRIP_LOGICAL_TYPES_SCHEMA .getField ("dec_fixed_large" ).schema ();
696- rec .put ("dec_fixed_large" , decimalConversions .toFixed (above
697- ? decFixedLargeThreshold .add (incLargeScale9 )
698- : decFixedLargeThreshold .subtract (incLargeScale9 ), decFixedLargeSchema , LogicalTypes .decimal (18 , 9 )));
699665 generateTripSuffixValues (rec , isDeleteRecord );
700666 return new RawTripTestPayload (rec .toString (), key .getRecordKey (), key .getPartitionPath (), rec .getSchema ().toString ());
701667 }
@@ -1139,9 +1105,13 @@ public Stream<HoodieRecord> generateUniqueUpdatesStream(String instantTime, Inte
11391105 * @return stream of hoodie record updates
11401106 */
11411107 public Stream <HoodieKey > generateUniqueDeleteStream (Integer n ) {
1108+ return generateUniqueDeleteStream (n , TRIP_EXAMPLE_SCHEMA );
1109+ }
1110+
1111+ public Stream <HoodieKey > generateUniqueDeleteStream (Integer n , String streamStr ) {
11421112 final Set <KeyPartition > used = new HashSet <>();
1143- Map <Integer , KeyPartition > existingKeys = existingKeysBySchema .get (TRIP_EXAMPLE_SCHEMA );
1144- Integer numExistingKeys = numKeysBySchema .get (TRIP_EXAMPLE_SCHEMA );
1113+ Map <Integer , KeyPartition > existingKeys = existingKeysBySchema .get (streamStr );
1114+ Integer numExistingKeys = numKeysBySchema .get (streamStr );
11451115 if (n > numExistingKeys ) {
11461116 throw new IllegalArgumentException ("Requested unique deletes is greater than number of available keys" );
11471117 }
@@ -1159,7 +1129,7 @@ public Stream<HoodieKey> generateUniqueDeleteStream(Integer n) {
11591129 used .add (kp );
11601130 result .add (kp .key );
11611131 }
1162- numKeysBySchema .put (TRIP_EXAMPLE_SCHEMA , numExistingKeys );
1132+ numKeysBySchema .put (streamStr , numExistingKeys );
11631133 return result .stream ();
11641134 }
11651135
@@ -1171,9 +1141,13 @@ public Stream<HoodieKey> generateUniqueDeleteStream(Integer n) {
11711141 * @return stream of hoodie records for delete
11721142 */
11731143 public Stream <HoodieRecord > generateUniqueDeleteRecordStream (String instantTime , Integer n ) {
1144+ return generateUniqueDeleteRecordStream (instantTime , n , TRIP_EXAMPLE_SCHEMA );
1145+ }
1146+
1147+ public Stream <HoodieRecord > generateUniqueDeleteRecordStream (String instantTime , Integer n , String schemaStr ) {
11741148 final Set <KeyPartition > used = new HashSet <>();
1175- Map <Integer , KeyPartition > existingKeys = existingKeysBySchema .get (TRIP_EXAMPLE_SCHEMA );
1176- Integer numExistingKeys = numKeysBySchema .get (TRIP_EXAMPLE_SCHEMA );
1149+ Map <Integer , KeyPartition > existingKeys = existingKeysBySchema .get (schemaStr );
1150+ Integer numExistingKeys = numKeysBySchema .get (schemaStr );
11771151 if (n > numExistingKeys ) {
11781152 throw new IllegalArgumentException ("Requested unique deletes is greater than number of available keys" );
11791153 }
@@ -1191,12 +1165,12 @@ public Stream<HoodieRecord> generateUniqueDeleteRecordStream(String instantTime,
11911165 numExistingKeys --;
11921166 used .add (kp );
11931167 try {
1194- result .add (new HoodieAvroRecord (kp .key , generateRandomDeleteValue (kp .key , instantTime )));
1168+ result .add (new HoodieAvroRecord (kp .key , generateRandomDeleteValuePerSchema (kp .key , instantTime , schemaStr )));
11951169 } catch (IOException e ) {
11961170 throw new HoodieIOException (e .getMessage (), e );
11971171 }
11981172 }
1199- numKeysBySchema .put (TRIP_EXAMPLE_SCHEMA , numExistingKeys );
1173+ numKeysBySchema .put (schemaStr , numExistingKeys );
12001174 return result .stream ();
12011175 }
12021176
@@ -1262,7 +1236,7 @@ public void close() {
12621236
12631237 private static long genRandomTimeMillis (Random r ) {
12641238 // Fri Feb 13 15:31:30 PST 2009
1265- long anchorTs = 1234567890L ;
1239+ long anchorTs = 1234567890000L ;
12661240 // NOTE: To provide for certainty and not generate overly random dates, we will limit
12671241 // dispersion to be w/in +/- 3 days from the anchor date
12681242 return anchorTs + r .nextLong () % 259200000L ;
0 commit comments