@@ -455,15 +455,19 @@ public void testSchema(String ksName) throws InterruptedException, IOException {
455455 dataSpecMap .get ("map" ).cqlValue
456456 );
457457
458+ // force udt values to be null by populating 1 item, using zudt.newValue() without explicitly setting
459+ // any field to non-null value will cause the udt column itself to be null in the C* table
460+ UdtValue zudtOptionalValues = zudt .newValue (dataSpecMap .get ("text" ).cqlValue );
461+
458462 cqlSession .execute ("CREATE TABLE IF NOT EXISTS " + ksName + ".table3 (" +
459463 "xtext text, xascii ascii, xboolean boolean, xblob blob, xtimestamp timestamp, xtime time, xdate date, xuuid uuid, xtimeuuid timeuuid, xtinyint tinyint, xsmallint smallint, xint int, xbigint bigint, xvarint varint, xdecimal decimal, xdouble double, xfloat float, xinet4 inet, xinet6 inet, " +
460- "ytext text, yascii ascii, yboolean boolean, yblob blob, ytimestamp timestamp, ytime time, ydate date, yuuid uuid, ytimeuuid timeuuid, ytinyint tinyint, ysmallint smallint, yint int, ybigint bigint, yvarint varint, ydecimal decimal, ydouble double, yfloat float, yinet4 inet, yinet6 inet, yduration duration, yudt zudt, ylist list<text>, yset set<int>, ymap map<text, double>, ylistofmap list<frozen<map<text,double>>>, ysetofudt set<frozen<zudt>>," +
464+ "ytext text, yascii ascii, yboolean boolean, yblob blob, ytimestamp timestamp, ytime time, ydate date, yuuid uuid, ytimeuuid timeuuid, ytinyint tinyint, ysmallint smallint, yint int, ybigint bigint, yvarint varint, ydecimal decimal, ydouble double, yfloat float, yinet4 inet, yinet6 inet, yduration duration, yudt zudt, yudtoptional zudt, ylist list<text>, yset set<int>, ymap map<text, double>, ylistofmap list<frozen<map<text,double>>>, ysetofudt set<frozen<zudt>>," +
461465 "primary key (xtext, xascii, xboolean, xblob, xtimestamp, xtime, xdate, xuuid, xtimeuuid, xtinyint, xsmallint, xint, xbigint, xvarint, xdecimal, xdouble, xfloat, xinet4, xinet6)) " +
462466 "WITH CLUSTERING ORDER BY (xascii ASC, xboolean DESC, xblob ASC, xtimestamp DESC, xtime DESC, xdate ASC, xuuid DESC, xtimeuuid ASC, xtinyint DESC, xsmallint ASC, xint DESC, xbigint ASC, xvarint DESC, xdecimal ASC, xdouble DESC, xfloat ASC, xinet4 ASC, xinet6 DESC) AND cdc=true" );
463467 cqlSession .execute ("INSERT INTO " + ksName + ".table3 (" +
464468 "xtext, xascii, xboolean, xblob, xtimestamp, xtime, xdate, xuuid, xtimeuuid, xtinyint, xsmallint, xint, xbigint, xvarint, xdecimal, xdouble, xfloat, xinet4, xinet6, " +
465- "ytext, yascii, yboolean, yblob, ytimestamp, ytime, ydate, yuuid, ytimeuuid, ytinyint, ysmallint, yint, ybigint, yvarint, ydecimal, ydouble, yfloat, yinet4, yinet6, yduration, yudt, ylist, yset, ymap, ylistofmap, ysetofudt" +
466- ") VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?, ?,?,?,?,?)" ,
469+ "ytext, yascii, yboolean, yblob, ytimestamp, ytime, ydate, yuuid, ytimeuuid, ytinyint, ysmallint, yint, ybigint, yvarint, ydecimal, ydouble, yfloat, yinet4, yinet6, yduration, yudt, yudtoptional, ylist, yset, ymap, ylistofmap, ysetofudt" +
470+ ") VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?, ?,?,?,?,?)" ,
467471 dataSpecMap .get ("text" ).cqlValue ,
468472 dataSpecMap .get ("ascii" ).cqlValue ,
469473 dataSpecMap .get ("boolean" ).cqlValue ,
@@ -506,6 +510,7 @@ public void testSchema(String ksName) throws InterruptedException, IOException {
506510
507511 dataSpecMap .get ("duration" ).cqlValue ,
508512 zudtValue ,
513+ zudtOptionalValues ,
509514
510515 dataSpecMap .get ("list" ).cqlValue ,
511516 dataSpecMap .get ("set" ).cqlValue ,
@@ -615,7 +620,7 @@ void assertGenericArray(String field, GenericArray ga) {
615620
616621 void assertField (String fieldName , Object value ) {
617622 String vKey = fieldName .substring (1 );
618- if (!vKey .equals ("udt" ) && ! vKey .equals ("setofudt" )) {
623+ if (!vKey .equals ("udt" ) && !vKey . equals ( "udtoptional" ) && ! vKey .equals ("setofudt" )) {
619624 Assert .assertTrue ("Unknown field " + vKey , dataSpecMap .containsKey (vKey ));
620625 }
621626 if (value instanceof GenericRecord ) {
@@ -672,6 +677,17 @@ void assertGenericRecords(String field, GenericRecord gr) {
672677 }
673678 }
674679 return ;
680+ case "udtoptional" : {
681+ for (Field f : gr .getFields ()) {
682+ if (f .getName ().equals ("ztext" )){
683+ assertField (f .getName (), gr .getField (f .getName ()));
684+ }
685+ else {
686+ assertNull (gr .getField (f .getName ()));
687+ }
688+ }
689+ }
690+ return ;
675691 }
676692 Assert .assertTrue ("Unexpected field=" +field , false );
677693 }
@@ -781,6 +797,17 @@ void assertJsonNode(String field, JsonNode node) {
781797 }
782798 }
783799 return ;
800+ case "udtoptional" : {
801+ for (Iterator <Map .Entry <String , JsonNode >> it = node .fields (); it .hasNext (); ) {
802+ Map .Entry <String , JsonNode > f = it .next ();
803+ if (f .getKey ().equals ("ztext" )) {
804+ assertField (f .getKey (), f .getValue ());
805+ } else {
806+ assertNull (f .getValue ());
807+ }
808+ }
809+ }
810+ return ;
784811 }
785812 Assert .assertTrue ("Unexpected field=" +field , false );
786813 }
0 commit comments