@@ -4696,4 +4696,86 @@ public void evalFieldWithSingleQuotes() {
46964696 Assertions .assertEquals ("string" , r .getAs (0 ));
46974697 });
46984698 }
4699+
4700+ @ Test
4701+ @ DisabledIfSystemProperty (
4702+ named = "skipSparkTest" ,
4703+ matches = "true"
4704+ )
4705+ public void testEvalMatchNullsOnlySubject () {
4706+ String q = "index=index_A | eval a=null() | eval b=if(match(a,\" 3\" ),1,0)" ;
4707+ String testFile = "src/test/resources/eval_test_ips*.jsonl" ; // * to make the path into a directory path
4708+
4709+ streamingTestUtil .performDPLTest (q , testFile , res -> {
4710+ final StructType expectedSchema = new StructType (new StructField [] {
4711+ new StructField ("_raw" , DataTypes .StringType , true , new MetadataBuilder ().build ()),
4712+ new StructField ("_time" , DataTypes .TimestampType , true , new MetadataBuilder ().build ()),
4713+ new StructField ("host" , DataTypes .StringType , true , new MetadataBuilder ().build ()),
4714+ new StructField ("index" , DataTypes .StringType , true , new MetadataBuilder ().build ()),
4715+ new StructField ("ip" , DataTypes .StringType , true , new MetadataBuilder ().build ()),
4716+ new StructField ("offset" , DataTypes .LongType , true , new MetadataBuilder ().build ()),
4717+ new StructField ("partition" , DataTypes .StringType , true , new MetadataBuilder ().build ()),
4718+ new StructField ("source" , DataTypes .StringType , true , new MetadataBuilder ().build ()),
4719+ new StructField ("sourcetype" , DataTypes .StringType , true , new MetadataBuilder ().build ()),
4720+ new StructField ("a" , DataTypes .StringType , true , new MetadataBuilder ().build ()),
4721+ new StructField ("b" , DataTypes .createArrayType (DataTypes .StringType , true ), true , new MetadataBuilder ().build ())
4722+ });
4723+ Assertions .assertEquals (expectedSchema , res .schema ()); //check schema
4724+ // Get column 'a'
4725+ Dataset <Row > resA = res .select ("b" ).orderBy ("offset" );
4726+ List <String > lst = resA
4727+ .collectAsList ()
4728+ .stream ()
4729+ .map (r -> r .getList (0 ).get (0 ).toString ())
4730+ .collect (Collectors .toList ());
4731+
4732+ // we should get the same amount of values back as we put in
4733+ Assertions .assertEquals (3 , lst .size ());
4734+ // Compare values to expected
4735+ List <String > expectedLst = Arrays .asList ("0" , "0" , "0" );
4736+
4737+ Assertions .assertEquals (expectedLst , lst );
4738+ });
4739+ }
4740+
4741+ @ Test
4742+ @ DisabledIfSystemProperty (
4743+ named = "skipSparkTest" ,
4744+ matches = "true"
4745+ )
4746+ public void testEvalMatchSubjectWithSomeNUlls () {
4747+ String q = "index=index_A | eval a=if(match(sourcetype,\" X\" ),1,0)" ;
4748+ String testFile = "src/test/resources/eval_test_ips*.jsonl" ; // * to make the path into a directory path
4749+
4750+ streamingTestUtil .performDPLTest (q , testFile , res -> {
4751+ final StructType expectedSchema = new StructType (new StructField [] {
4752+ new StructField ("_raw" , DataTypes .StringType , true , new MetadataBuilder ().build ()),
4753+ new StructField ("_time" , DataTypes .TimestampType , true , new MetadataBuilder ().build ()),
4754+ new StructField ("host" , DataTypes .StringType , true , new MetadataBuilder ().build ()),
4755+ new StructField ("index" , DataTypes .StringType , true , new MetadataBuilder ().build ()),
4756+ new StructField ("ip" , DataTypes .StringType , true , new MetadataBuilder ().build ()),
4757+ new StructField ("offset" , DataTypes .LongType , true , new MetadataBuilder ().build ()),
4758+ new StructField ("partition" , DataTypes .StringType , true , new MetadataBuilder ().build ()),
4759+ new StructField ("source" , DataTypes .StringType , true , new MetadataBuilder ().build ()),
4760+ new StructField ("sourcetype" , DataTypes .StringType , true , new MetadataBuilder ().build ()),
4761+ new StructField ("a" , DataTypes .createArrayType (DataTypes .StringType , true ), true , new MetadataBuilder ().build ())
4762+ });
4763+ Assertions .assertEquals (expectedSchema , res .schema ()); //check schema
4764+ // Get column 'a'
4765+ Dataset <Row > resA = res .select ("a" ).orderBy ("offset" );
4766+ List <String > lst = resA
4767+ .collectAsList ()
4768+ .stream ()
4769+ .map (r -> r .getList (0 ).get (0 ).toString ())
4770+ .collect (Collectors .toList ());
4771+
4772+ // we should get the same amount of values back as we put in
4773+ Assertions .assertEquals (3 , lst .size ());
4774+ // Compare values to expected
4775+ List <String > expectedLst = Arrays .asList ("1" , "1" , "0" );
4776+
4777+ Assertions .assertEquals (expectedLst , lst );
4778+ });
4779+ }
4780+
46994781}
0 commit comments