github-code-scanning[bot] commented on code in PR #14421:
URL: https://github.com/apache/druid/pull/14421#discussion_r1228978039


##########
extensions-core/kafka-indexing-service/src/test/java/org/apache/druid/data/input/kafkainput/KafkaInputFormatTest.java:
##########
@@ -169,23 +192,40 @@
         + "    \"o\": {\n"
         + "        \"mg\": 1\n"
         + "    }\n"
-        + "}");
+        + "}"
+    );
 
     Headers headers = new RecordHeaders(SAMPLE_HEADERS);
-    inputEntity = new KafkaRecordEntity(new ConsumerRecord<byte[], byte[]>(
-        "sample", 0, 0, timestamp,
-        null, null, 0, 0,
-        key, payload, headers));
+    inputEntity = new KafkaRecordEntity(
+        new ConsumerRecord<>(
+            "sample",
+            0,
+            0,
+            timestamp,
+            null,
+            null,
+            0,
+            0,
+            key,
+            payload,
+            headers
+        )

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [ConsumerRecord.ConsumerRecord](1) should be avoided because it has 
been deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/5051)



##########
extensions-core/kafka-indexing-service/src/test/java/org/apache/druid/data/input/kafkainput/KafkaInputFormatTest.java:
##########
@@ -389,13 +492,25 @@
         + "    \"o\": {\n"
         + "        \"mg\": 1\n"
         + "    }\n"
-        + "}");
+        + "}"
+    );
 
     Headers headers = new RecordHeaders(SAMPLE_HEADERS);
-    inputEntity = new KafkaRecordEntity(new ConsumerRecord<byte[], byte[]>(
-        "sample", 0, 0, timestamp,
-        null, null, 0, 0,
-        null, payload, headers));
+    inputEntity = new KafkaRecordEntity(
+        new ConsumerRecord<>(
+            "sample",
+            0,
+            0,
+            timestamp,
+            null,
+            null,
+            0,
+            0,
+            null,
+            payload,
+            headers
+        )

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [ConsumerRecord.ConsumerRecord](1) should be avoided because it has 
been deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/5072)



##########
extensions-core/kafka-indexing-service/src/test/java/org/apache/druid/data/input/kafkainput/KafkaInputFormatTest.java:
##########
@@ -316,22 +393,39 @@
         + "    \"o\": {\n"
         + "        \"mg\": 1\n"
         + "    }\n"
-        + "}");
+        + "}"
+    );
 
     Headers headers = new RecordHeaders(sample_header_with_ts);
-    inputEntity = new KafkaRecordEntity(new ConsumerRecord<byte[], byte[]>(
-        "sample", 0, 0, timestamp,
-        null, null, 0, 0,
-        key, payload, headers));
+    inputEntity = new KafkaRecordEntity(
+        new ConsumerRecord<>(
+            "sample",
+            0,
+            0,
+            timestamp,
+            null,
+            null,
+            0,
+            0,
+            key,
+            payload,
+            headers
+        )

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [ConsumerRecord.ConsumerRecord](1) should be avoided because it has 
been deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/5071)



##########
extensions-core/kafka-indexing-service/src/test/java/org/apache/druid/data/input/kafkainput/KafkaInputFormatTest.java:
##########
@@ -617,6 +771,230 @@
     }
   }
 
+  @Test
+  public void testWithSchemaDiscovery() throws IOException
+  {
+    // testWithHeaderKeyAndValue + schemaless
+    final byte[] key = StringUtils.toUtf8(
+        "{\n"
+        + "    \"key\": \"sampleKey\"\n"
+        + "}"
+    );
+
+    final byte[] payload = StringUtils.toUtf8(
+        "{\n"
+        + "    \"timestamp\": \"2021-06-25\",\n"
+        + "    \"bar\": null,\n"
+        + "    \"foo\": \"x\",\n"
+        + "    \"baz\": 4,\n"
+        + "    \"o\": {\n"
+        + "        \"mg\": 1\n"
+        + "    }\n"
+        + "}"
+    );
+
+    Headers headers = new RecordHeaders(SAMPLE_HEADERS);
+    inputEntity = new KafkaRecordEntity(
+        new ConsumerRecord<>(
+            "sample",
+            0,
+            0,
+            timestamp,
+            null,
+            null,
+            0,
+            0,
+            key,
+            payload,
+            headers
+        )
+    );
+
+    final InputEntityReader reader = format.createReader(
+        new InputRowSchema(
+            new TimestampSpec("timestamp", "iso", null),
+            DimensionsSpec.builder().useSchemaDiscovery(true).build(),
+            ColumnsFilter.all()
+        ),
+        newSettableByteEntity(inputEntity),
+        null
+    );
+
+    final int numExpectedIterations = 1;
+    try (CloseableIterator<InputRow> iterator = reader.read()) {
+      int numActualIterations = 0;
+      while (iterator.hasNext()) {
+
+        final InputRow row = iterator.next();
+        Assert.assertEquals(
+            Arrays.asList(
+                "foo",
+                "kafka.newts.timestamp",
+                "kafka.newkey.key",
+                "root_baz",
+                "o",
+                "bar",
+                "kafka.newheader.kafkapkc",
+                "path_omg",
+                "jq_omg",
+                "jq_omg2",
+                "baz",
+                "root_baz2",
+                "kafka.newheader.encoding",
+                "path_omg2"
+            ),
+            row.getDimensions()
+        );
+
+        // Payload verifications
+        Assert.assertEquals(DateTimes.of("2021-06-25"), row.getTimestamp());
+        Assert.assertEquals("x", 
Iterables.getOnlyElement(row.getDimension("foo")));
+        Assert.assertEquals("4", 
Iterables.getOnlyElement(row.getDimension("baz")));
+        Assert.assertEquals("4", 
Iterables.getOnlyElement(row.getDimension("root_baz")));
+        Assert.assertEquals("1", 
Iterables.getOnlyElement(row.getDimension("path_omg")));
+        Assert.assertEquals("1", 
Iterables.getOnlyElement(row.getDimension("jq_omg")));
+        Assert.assertEquals(ImmutableMap.of("mg", 1L), row.getRaw("o"));
+
+        // Header verification
+        Assert.assertEquals("application/json", 
Iterables.getOnlyElement(row.getDimension("kafka.newheader.encoding")));
+        Assert.assertEquals("pkc-bar", 
Iterables.getOnlyElement(row.getDimension("kafka.newheader.kafkapkc")));
+        Assert.assertEquals(
+            String.valueOf(DateTimes.of("2021-06-24").getMillis()),
+            Iterables.getOnlyElement(row.getDimension("kafka.newts.timestamp"))
+        );
+        Assert.assertEquals(
+            "2021-06-25",
+            Iterables.getOnlyElement(row.getDimension("timestamp"))
+        );
+
+        // Key verification
+        Assert.assertEquals("sampleKey", 
Iterables.getOnlyElement(row.getDimension("kafka.newkey.key")));
+
+        Assert.assertTrue(row.getDimension("root_baz2").isEmpty());
+        Assert.assertTrue(row.getDimension("path_omg2").isEmpty());
+        Assert.assertTrue(row.getDimension("jq_omg2").isEmpty());
+
+        numActualIterations++;
+      }
+
+      Assert.assertEquals(numExpectedIterations, numActualIterations);
+    }
+  }
+
+  @Test
+  public void testWithPartialDeclarationSchemaDiscovery() throws IOException
+  {
+    // testWithHeaderKeyAndValue + partial-schema + schema discovery
+    final byte[] key = StringUtils.toUtf8(
+        "{\n"
+        + "    \"key\": \"sampleKey\"\n"
+        + "}"
+    );
+
+    final byte[] payload = StringUtils.toUtf8(
+        "{\n"
+        + "    \"timestamp\": \"2021-06-25\",\n"
+        + "    \"bar\": null,\n"
+        + "    \"foo\": \"x\",\n"
+        + "    \"baz\": 4,\n"
+        + "    \"o\": {\n"
+        + "        \"mg\": 1\n"
+        + "    }\n"
+        + "}"
+    );
+
+    Headers headers = new RecordHeaders(SAMPLE_HEADERS);
+    inputEntity = new KafkaRecordEntity(
+        new ConsumerRecord<>(
+            "sample",
+            0,
+            0,
+            timestamp,
+            null,
+            null,
+            0,
+            0,
+            key,
+            payload,
+            headers
+        )

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [ConsumerRecord.ConsumerRecord](1) should be avoided because it has 
been deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/5076)



##########
extensions-core/kafka-indexing-service/src/test/java/org/apache/druid/data/input/kafkainput/KafkaInputFormatTest.java:
##########
@@ -504,10 +633,21 @@
     for (int i = 0; i < keys.length; i++) {
       headers = headers.add(new RecordHeader("indexH", 
String.valueOf(i).getBytes(StandardCharsets.UTF_8)));
 
-      inputEntity = new KafkaRecordEntity(new ConsumerRecord<>(
-          "sample", 0, 0, timestamp,
-          null, null, 0, 0,
-          keys[i], values[i], headers));
+      inputEntity = new KafkaRecordEntity(
+          new ConsumerRecord<>(
+              "sample",
+              0,
+              0,
+              timestamp,
+              null,
+              null,
+              0,
+              0,
+              keys[i],
+              values[i],
+              headers
+          )

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [ConsumerRecord.ConsumerRecord](1) should be avoided because it has 
been deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/5073)



##########
extensions-core/kafka-indexing-service/src/test/java/org/apache/druid/data/input/kafkainput/KafkaInputFormatTest.java:
##########
@@ -246,20 +302,36 @@
         + "}");
 
     Headers headers = new RecordHeaders(SAMPLE_HEADERS);
-    inputEntity = new KafkaRecordEntity(new ConsumerRecord<byte[], byte[]>(
-        "sample", 0, 0, timestamp,
-        null, null, 0, 0,
-        null, payload, headers));
+    inputEntity = new KafkaRecordEntity(
+        new ConsumerRecord<>(
+            "sample",
+            0,
+            0,
+            timestamp,
+            null,
+            null,
+            0,
+            0,
+            null,
+            payload,
+            headers
+        )

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [ConsumerRecord.ConsumerRecord](1) should be avoided because it has 
been deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/5070)



##########
extensions-core/kafka-indexing-service/src/test/java/org/apache/druid/data/input/kafkainput/KafkaInputFormatTest.java:
##########
@@ -617,6 +771,230 @@
     }
   }
 
+  @Test
+  public void testWithSchemaDiscovery() throws IOException
+  {
+    // testWithHeaderKeyAndValue + schemaless
+    final byte[] key = StringUtils.toUtf8(
+        "{\n"
+        + "    \"key\": \"sampleKey\"\n"
+        + "}"
+    );
+
+    final byte[] payload = StringUtils.toUtf8(
+        "{\n"
+        + "    \"timestamp\": \"2021-06-25\",\n"
+        + "    \"bar\": null,\n"
+        + "    \"foo\": \"x\",\n"
+        + "    \"baz\": 4,\n"
+        + "    \"o\": {\n"
+        + "        \"mg\": 1\n"
+        + "    }\n"
+        + "}"
+    );
+
+    Headers headers = new RecordHeaders(SAMPLE_HEADERS);
+    inputEntity = new KafkaRecordEntity(
+        new ConsumerRecord<>(
+            "sample",
+            0,
+            0,
+            timestamp,
+            null,
+            null,
+            0,
+            0,
+            key,
+            payload,
+            headers
+        )

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [ConsumerRecord.ConsumerRecord](1) should be avoided because it has 
been deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/5075)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to