You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "r-reis (via GitHub)" <gi...@apache.org> on 2025/03/14 13:51:51 UTC
[PR] feat(KafkaConfluentSchemaRegistryJsonMessageDecoder): added the JSON confluent schema decoder [pinot]
r-reis opened a new pull request, #15273:
URL: https://github.com/apache/pinot/pull/15273
Related to this [issue](https://github.com/apache/pinot/issues/15262)
The main change was the inclusion of confluent [JSONSchemaDeserializer](https://github.com/confluentinc/schema-registry/blob/master/json-schema-serializer/src/main/java/io/confluent/kafka/serializers/json/KafkaJsonSchemaDeserializer.java) to the input-format plugin.
Follow the instruction on the issue, but now we have a new decoder.class.name "org.apache.pinot.plugin.inputformat.json.confluent.KafkaConfluentSchemaRegistryJsonMessageDecoder"
Example of table config:
```
{
"tableName": "topic_1",
"tableType": "REALTIME",
"segmentsConfig": {
"timeColumnName": "created_at",
"timeType": "MILLISECONDS",
"replicasPerPartition": "1"
},
"tenants": {},
"tableIndexConfig": {
"loadMode": "MMAP",
"streamConfigs": {
"stream.kafka.metadata.populate" : "true",
"streamType": "kafka",
"stream.kafka.decoder.prop.format": "JSON",
"stream.kafka.consumer.type": "low-level",
"stream.kafka.topic.name": "topic_1",
"stream.kafka.decoder.class.name": "org.apache.pinot.plugin.inputformat.json.confluent.KafkaConfluentSchemaRegistryJsonMessageDecoder",
"stream.kafka.consumer.factory.class.name": "org.apache.pinot.plugin.stream.kafka30.KafkaConsumerFactory",
"stream.kafka.schema.registry.url": "http://localhost:8081",
"stream.kafka.decoder.prop.schema.registry.rest.url": "http://localhost:8081",
"stream.kafka.broker.list": "localhost:9092",
"realtime.segment.flush.threshold.rows": "0",
"realtime.segment.flush.threshold.time": "24h",
"realtime.segment.flush.threshold.segment.size": "50M",
"stream.kafka.consumer.prop.auto.offset.reset": "smallest",
"key.serializer": "shaded.org.apache.kafka.connect.storage.StringDeserializer",
"value.serializer": "shaded.org.apache.kafka.connect.storage.StringDeserializer"
}
},
"ingestionConfig": {
"continueOnError": true
},
"metadata": {
"customConfigs": {}
}
}
```
Handling all exceptions and errors is the same as AvroSchemaDecoder and ProtoBufSchemaDecoder.
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] feat(KafkaConfluentSchemaRegistryJsonMessageDecoder): added the JSON confluent schema decoder [pinot]
Posted by "mayankshriv (via GitHub)" <gi...@apache.org>.
mayankshriv merged PR #15273:
URL: https://github.com/apache/pinot/pull/15273
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] feat(KafkaConfluentSchemaRegistryJsonMessageDecoder): added the JSON confluent schema decoder [pinot]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #15273:
URL: https://github.com/apache/pinot/pull/15273#issuecomment-2725024335
## [Codecov](https://app.codecov.io/gh/apache/pinot/pull/15273?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 56.01%. Comparing base [(`59551e4`)](https://app.codecov.io/gh/apache/pinot/commit/59551e45224f1535c4863fd577622b37366ccc97?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`e024c0b`)](https://app.codecov.io/gh/apache/pinot/commit/e024c0b09a07b9dd3910d640c09c24f825ae099b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
> Report is 1843 commits behind head on master.
> :exclamation: There is a different number of reports uploaded between BASE (59551e4) and HEAD (e024c0b). Click for more details.
>
> <details><summary>HEAD has 53 uploads less than BASE</summary>
>
>| Flag | BASE (59551e4) | HEAD (e024c0b) |
>|------|------|------|
>|integration|7|0|
>|integration2|3|0|
>|temurin|12|1|
>|java-21|7|1|
>|skip-bytebuffers-true|3|0|
>|skip-bytebuffers-false|7|1|
>|unittests|5|1|
>|unittests1|2|1|
>|java-11|5|0|
>|unittests2|3|0|
>|integration1|2|0|
>|custom-integration1|2|0|
></details>
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #15273 +/- ##
============================================
- Coverage 61.75% 56.01% -5.74%
- Complexity 207 685 +478
============================================
Files 2436 2167 -269
Lines 133233 116862 -16371
Branches 20636 18704 -1932
============================================
- Hits 82274 65466 -16808
- Misses 44911 46009 +1098
+ Partials 6048 5387 -661
```
| [Flag](https://app.codecov.io/gh/apache/pinot/pull/15273/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [custom-integration1](https://app.codecov.io/gh/apache/pinot/pull/15273/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [integration](https://app.codecov.io/gh/apache/pinot/pull/15273/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [integration1](https://app.codecov.io/gh/apache/pinot/pull/15273/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [integration2](https://app.codecov.io/gh/apache/pinot/pull/15273/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [java-11](https://app.codecov.io/gh/apache/pinot/pull/15273/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [java-21](https://app.codecov.io/gh/apache/pinot/pull/15273/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `56.01% <ø> (-5.61%)` | :arrow_down: |
| [skip-bytebuffers-false](https://app.codecov.io/gh/apache/pinot/pull/15273/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `56.01% <ø> (-5.73%)` | :arrow_down: |
| [skip-bytebuffers-true](https://app.codecov.io/gh/apache/pinot/pull/15273/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [temurin](https://app.codecov.io/gh/apache/pinot/pull/15273/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `56.01% <ø> (-5.74%)` | :arrow_down: |
| [unittests](https://app.codecov.io/gh/apache/pinot/pull/15273/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `56.01% <ø> (-5.73%)` | :arrow_down: |
| [unittests1](https://app.codecov.io/gh/apache/pinot/pull/15273/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `56.01% <ø> (+9.12%)` | :arrow_up: |
| [unittests2](https://app.codecov.io/gh/apache/pinot/pull/15273/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/pinot/pull/15273?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary>🚀 New features to boost your workflow: </summary>
- ❄ [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- 📦 [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] feat(KafkaConfluentSchemaRegistryJsonMessageDecoder): added the JSON confluent schema decoder [pinot]
Posted by "r-reis (via GitHub)" <gi...@apache.org>.
r-reis commented on code in PR #15273:
URL: https://github.com/apache/pinot/pull/15273#discussion_r2002118563
##########
pom.xml:
##########
@@ -1929,6 +1939,11 @@
<artifactId>kotlin-reflect</artifactId>
<version>${kotlin.stdlib.version}</version>
</dependency>
+ <dependency>
Review Comment:
It was a leftover from a previous tests.
Fixed and ty.
##########
pom.xml:
##########
@@ -1929,6 +1939,11 @@
<artifactId>kotlin-reflect</artifactId>
<version>${kotlin.stdlib.version}</version>
</dependency>
+ <dependency>
Review Comment:
It was a leftover from previous tests.
Fixed and ty.
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] feat(KafkaConfluentSchemaRegistryJsonMessageDecoder): added the JSON confluent schema decoder [pinot]
Posted by "r-reis (via GitHub)" <gi...@apache.org>.
r-reis commented on code in PR #15273:
URL: https://github.com/apache/pinot/pull/15273#discussion_r2002119762
##########
pinot-plugins/pinot-input-format/pinot-confluent-json/src/main/java/org/apache/pinot/plugin/inputformat/json/confluent/KafkaConfluentSchemaRegistryJsonMessageDecoder.java:
##########
@@ -0,0 +1,153 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.plugin.inputformat.json.confluent;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.base.Preconditions;
+import io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient;
+import io.confluent.kafka.schemaregistry.client.SchemaRegistryClient;
+import io.confluent.kafka.schemaregistry.client.rest.RestService;
+import io.confluent.kafka.schemaregistry.json.JsonSchemaProvider;
+import io.confluent.kafka.serializers.json.KafkaJsonSchemaDeserializer;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import org.apache.kafka.common.config.ConfigDef;
+import org.apache.kafka.common.config.SslConfigs;
+import org.apache.kafka.common.config.types.Password;
+import org.apache.kafka.common.errors.SerializationException;
+import org.apache.kafka.common.security.ssl.DefaultSslEngineFactory;
+import org.apache.pinot.plugin.inputformat.json.JSONRecordExtractor;
+import org.apache.pinot.spi.data.readers.GenericRow;
+import org.apache.pinot.spi.data.readers.RecordExtractor;
+import org.apache.pinot.spi.plugin.PluginManager;
+import org.apache.pinot.spi.stream.StreamMessageDecoder;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static com.google.common.base.Preconditions.checkState;
+
+
+/**
+ * Decodes avro messages with confluent schema registry.
+ * First byte is MAGIC = 0, second 4 bytes are the schema id, the remainder is the value.
+ * NOTE: Do not use schema in the implementation, as schema will be removed from the params
+ */
+public class KafkaConfluentSchemaRegistryJsonMessageDecoder implements StreamMessageDecoder<byte[]> {
+ private static final Logger LOGGER = LoggerFactory.getLogger(KafkaConfluentSchemaRegistryJsonMessageDecoder.class);
+ private static final String SCHEMA_REGISTRY_REST_URL = "schema.registry.rest.url";
+ private static final String SCHEMA_REGISTRY_OPTS_PREFIX = "schema.registry.";
+ public static final String CACHED_SCHEMA_MAP_CAPACITY = "cached.schema.map.capacity";
+ public static final String DEFAULT_CACHED_SCHEMA_MAP_CAPACITY = "1000";
+ private KafkaJsonSchemaDeserializer _deserializer;
+ private RecordExtractor<Map<String, Object>> _jsonRecordExtractor;
+ private String _topicName;
+
+ public RestService createRestService(String schemaRegistryUrl, Map<String, String> configs) {
+ RestService restService = new RestService(schemaRegistryUrl);
+
+ ConfigDef configDef = new ConfigDef();
+ SslConfigs.addClientSslSupport(configDef);
+ Map<String, ConfigDef.ConfigKey> configKeyMap = configDef.configKeys();
+ Map<String, Object> sslConfigs = new HashMap<>();
+ for (String key : configs.keySet()) {
+ if (!key.equals(SCHEMA_REGISTRY_REST_URL) && key.startsWith(SCHEMA_REGISTRY_OPTS_PREFIX)) {
+ String value = configs.get(key);
+ String schemaRegistryOptKey = key.substring(SCHEMA_REGISTRY_OPTS_PREFIX.length());
+
+ if (configKeyMap.containsKey(schemaRegistryOptKey)) {
+ if (configKeyMap.get(schemaRegistryOptKey).type == ConfigDef.Type.PASSWORD) {
+ sslConfigs.put(schemaRegistryOptKey, new Password(value));
+ } else {
+ sslConfigs.put(schemaRegistryOptKey, value);
+ }
+ }
+ }
+ }
+
+ if (!sslConfigs.isEmpty()) {
+ DefaultSslEngineFactory sslFactory = new DefaultSslEngineFactory();
+ sslFactory.configure(sslConfigs);
+ restService.setSslSocketFactory(sslFactory.sslContext().getSocketFactory());
+ }
+ return restService;
+ }
+
+ @Override
+ public void init(Map<String, String> props, Set<String> fieldsToRead, String topicName)
+ throws Exception {
+ checkState(props.containsKey(SCHEMA_REGISTRY_REST_URL), "Missing required property '%s'", SCHEMA_REGISTRY_REST_URL);
+ String schemaRegistryUrl = props.get(SCHEMA_REGISTRY_REST_URL);
+ JsonSchemaProvider jsonSchemaProvider = new JsonSchemaProvider();
+ int identityMapCapacity = Integer.parseInt(
+ props.getOrDefault(CACHED_SCHEMA_MAP_CAPACITY, DEFAULT_CACHED_SCHEMA_MAP_CAPACITY));
+ SchemaRegistryClient schemaRegistryClient =
+ new CachedSchemaRegistryClient(createRestService(schemaRegistryUrl, props), identityMapCapacity,
+ Collections.singletonList(jsonSchemaProvider), props, null);
+
+ _deserializer = new KafkaJsonSchemaDeserializer(schemaRegistryClient);
+ Preconditions.checkNotNull(topicName, "Topic must be provided");
+ _topicName = topicName;
+ _jsonRecordExtractor = PluginManager.get().createInstance(JSONRecordExtractor.class.getName());
+ _jsonRecordExtractor.init(fieldsToRead, null);
+ }
+
+ @Override
+ public GenericRow decode(byte[] payload, GenericRow destination) {
+ try {
+ JsonNode jsonRecord = (JsonNode) _deserializer.deserialize(_topicName, payload);
+ Map<String, Object> from = JsonUtils.jsonNodeToMap(jsonRecord);
+ return _jsonRecordExtractor.extract(from, destination);
+ } catch (RuntimeException e) {
+ ignoreOrRethrowException(e);
+ return null;
+ } catch (Exception e) {
+ LOGGER.error("Caught exception while decoding row, discarding row. Payload is {}", new String(payload), e);
+ return null;
+ }
Review Comment:
Fixed in the new commit, but I had to add an IOException handle due to the jsonNodeToMap function.
##########
pinot-plugins/pinot-input-format/pinot-confluent-json/src/main/java/org/apache/pinot/plugin/inputformat/json/confluent/KafkaConfluentSchemaRegistryJsonMessageDecoder.java:
##########
@@ -0,0 +1,153 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.plugin.inputformat.json.confluent;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.base.Preconditions;
+import io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient;
+import io.confluent.kafka.schemaregistry.client.SchemaRegistryClient;
+import io.confluent.kafka.schemaregistry.client.rest.RestService;
+import io.confluent.kafka.schemaregistry.json.JsonSchemaProvider;
+import io.confluent.kafka.serializers.json.KafkaJsonSchemaDeserializer;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import org.apache.kafka.common.config.ConfigDef;
+import org.apache.kafka.common.config.SslConfigs;
+import org.apache.kafka.common.config.types.Password;
+import org.apache.kafka.common.errors.SerializationException;
+import org.apache.kafka.common.security.ssl.DefaultSslEngineFactory;
+import org.apache.pinot.plugin.inputformat.json.JSONRecordExtractor;
+import org.apache.pinot.spi.data.readers.GenericRow;
+import org.apache.pinot.spi.data.readers.RecordExtractor;
+import org.apache.pinot.spi.plugin.PluginManager;
+import org.apache.pinot.spi.stream.StreamMessageDecoder;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static com.google.common.base.Preconditions.checkState;
+
+
+/**
+ * Decodes avro messages with confluent schema registry.
+ * First byte is MAGIC = 0, second 4 bytes are the schema id, the remainder is the value.
+ * NOTE: Do not use schema in the implementation, as schema will be removed from the params
+ */
+public class KafkaConfluentSchemaRegistryJsonMessageDecoder implements StreamMessageDecoder<byte[]> {
+ private static final Logger LOGGER = LoggerFactory.getLogger(KafkaConfluentSchemaRegistryJsonMessageDecoder.class);
+ private static final String SCHEMA_REGISTRY_REST_URL = "schema.registry.rest.url";
+ private static final String SCHEMA_REGISTRY_OPTS_PREFIX = "schema.registry.";
+ public static final String CACHED_SCHEMA_MAP_CAPACITY = "cached.schema.map.capacity";
+ public static final String DEFAULT_CACHED_SCHEMA_MAP_CAPACITY = "1000";
+ private KafkaJsonSchemaDeserializer _deserializer;
+ private RecordExtractor<Map<String, Object>> _jsonRecordExtractor;
+ private String _topicName;
+
+ public RestService createRestService(String schemaRegistryUrl, Map<String, String> configs) {
+ RestService restService = new RestService(schemaRegistryUrl);
+
+ ConfigDef configDef = new ConfigDef();
+ SslConfigs.addClientSslSupport(configDef);
+ Map<String, ConfigDef.ConfigKey> configKeyMap = configDef.configKeys();
+ Map<String, Object> sslConfigs = new HashMap<>();
+ for (String key : configs.keySet()) {
+ if (!key.equals(SCHEMA_REGISTRY_REST_URL) && key.startsWith(SCHEMA_REGISTRY_OPTS_PREFIX)) {
+ String value = configs.get(key);
+ String schemaRegistryOptKey = key.substring(SCHEMA_REGISTRY_OPTS_PREFIX.length());
+
+ if (configKeyMap.containsKey(schemaRegistryOptKey)) {
+ if (configKeyMap.get(schemaRegistryOptKey).type == ConfigDef.Type.PASSWORD) {
+ sslConfigs.put(schemaRegistryOptKey, new Password(value));
+ } else {
+ sslConfigs.put(schemaRegistryOptKey, value);
+ }
+ }
+ }
+ }
+
+ if (!sslConfigs.isEmpty()) {
+ DefaultSslEngineFactory sslFactory = new DefaultSslEngineFactory();
+ sslFactory.configure(sslConfigs);
+ restService.setSslSocketFactory(sslFactory.sslContext().getSocketFactory());
+ }
+ return restService;
+ }
+
+ @Override
+ public void init(Map<String, String> props, Set<String> fieldsToRead, String topicName)
+ throws Exception {
+ checkState(props.containsKey(SCHEMA_REGISTRY_REST_URL), "Missing required property '%s'", SCHEMA_REGISTRY_REST_URL);
+ String schemaRegistryUrl = props.get(SCHEMA_REGISTRY_REST_URL);
+ JsonSchemaProvider jsonSchemaProvider = new JsonSchemaProvider();
+ int identityMapCapacity = Integer.parseInt(
+ props.getOrDefault(CACHED_SCHEMA_MAP_CAPACITY, DEFAULT_CACHED_SCHEMA_MAP_CAPACITY));
+ SchemaRegistryClient schemaRegistryClient =
+ new CachedSchemaRegistryClient(createRestService(schemaRegistryUrl, props), identityMapCapacity,
+ Collections.singletonList(jsonSchemaProvider), props, null);
+
+ _deserializer = new KafkaJsonSchemaDeserializer(schemaRegistryClient);
+ Preconditions.checkNotNull(topicName, "Topic must be provided");
+ _topicName = topicName;
+ _jsonRecordExtractor = PluginManager.get().createInstance(JSONRecordExtractor.class.getName());
+ _jsonRecordExtractor.init(fieldsToRead, null);
+ }
+
+ @Override
+ public GenericRow decode(byte[] payload, GenericRow destination) {
+ try {
+ JsonNode jsonRecord = (JsonNode) _deserializer.deserialize(_topicName, payload);
+ Map<String, Object> from = JsonUtils.jsonNodeToMap(jsonRecord);
+ return _jsonRecordExtractor.extract(from, destination);
+ } catch (RuntimeException e) {
+ ignoreOrRethrowException(e);
+ return null;
+ } catch (Exception e) {
+ LOGGER.error("Caught exception while decoding row, discarding row. Payload is {}", new String(payload), e);
+ return null;
+ }
Review Comment:
It was fixed in the new commit, but I had to add an IOException handle due to the jsonNodeToMap function.
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] feat(KafkaConfluentSchemaRegistryJsonMessageDecoder): added the JSON confluent schema decoder [pinot]
Posted by "mayankshriv (via GitHub)" <gi...@apache.org>.
mayankshriv commented on PR #15273:
URL: https://github.com/apache/pinot/pull/15273#issuecomment-2724919138
Thanks for reporting the issue and proposing a fix.
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] feat(KafkaConfluentSchemaRegistryJsonMessageDecoder): added the JSON confluent schema decoder [pinot]
Posted by "rajagopr (via GitHub)" <gi...@apache.org>.
rajagopr commented on PR #15273:
URL: https://github.com/apache/pinot/pull/15273#issuecomment-2739042916
Please address the checkstyle failures.
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] feat(KafkaConfluentSchemaRegistryJsonMessageDecoder): added the JSON confluent schema decoder [pinot]
Posted by "r-reis (via GitHub)" <gi...@apache.org>.
r-reis commented on code in PR #15273:
URL: https://github.com/apache/pinot/pull/15273#discussion_r2002118175
##########
pinot-plugins/pinot-input-format/pinot-confluent-json/src/main/java/org/apache/pinot/plugin/inputformat/json/confluent/KafkaConfluentSchemaRegistryJsonMessageDecoder.java:
##########
@@ -0,0 +1,153 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.plugin.inputformat.json.confluent;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.base.Preconditions;
+import io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient;
+import io.confluent.kafka.schemaregistry.client.SchemaRegistryClient;
+import io.confluent.kafka.schemaregistry.client.rest.RestService;
+import io.confluent.kafka.schemaregistry.json.JsonSchemaProvider;
+import io.confluent.kafka.serializers.json.KafkaJsonSchemaDeserializer;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import org.apache.kafka.common.config.ConfigDef;
+import org.apache.kafka.common.config.SslConfigs;
+import org.apache.kafka.common.config.types.Password;
+import org.apache.kafka.common.errors.SerializationException;
+import org.apache.kafka.common.security.ssl.DefaultSslEngineFactory;
+import org.apache.pinot.plugin.inputformat.json.JSONRecordExtractor;
+import org.apache.pinot.spi.data.readers.GenericRow;
+import org.apache.pinot.spi.data.readers.RecordExtractor;
+import org.apache.pinot.spi.plugin.PluginManager;
+import org.apache.pinot.spi.stream.StreamMessageDecoder;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static com.google.common.base.Preconditions.checkState;
+
+
+/**
+ * Decodes avro messages with confluent schema registry.
+ * First byte is MAGIC = 0, second 4 bytes are the schema id, the remainder is the value.
+ * NOTE: Do not use schema in the implementation, as schema will be removed from the params
+ */
+public class KafkaConfluentSchemaRegistryJsonMessageDecoder implements StreamMessageDecoder<byte[]> {
Review Comment:
Done!
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
Re: [PR] feat(KafkaConfluentSchemaRegistryJsonMessageDecoder): added the JSON confluent schema decoder [pinot]
Posted by "rajagopr (via GitHub)" <gi...@apache.org>.
rajagopr commented on code in PR #15273:
URL: https://github.com/apache/pinot/pull/15273#discussion_r1999820449
##########
pom.xml:
##########
@@ -1929,6 +1939,11 @@
<artifactId>kotlin-reflect</artifactId>
<version>${kotlin.stdlib.version}</version>
</dependency>
+ <dependency>
Review Comment:
Why do we need this plugin?
##########
pinot-plugins/pinot-input-format/pinot-confluent-json/src/main/java/org/apache/pinot/plugin/inputformat/json/confluent/KafkaConfluentSchemaRegistryJsonMessageDecoder.java:
##########
@@ -0,0 +1,153 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.plugin.inputformat.json.confluent;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.base.Preconditions;
+import io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient;
+import io.confluent.kafka.schemaregistry.client.SchemaRegistryClient;
+import io.confluent.kafka.schemaregistry.client.rest.RestService;
+import io.confluent.kafka.schemaregistry.json.JsonSchemaProvider;
+import io.confluent.kafka.serializers.json.KafkaJsonSchemaDeserializer;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import org.apache.kafka.common.config.ConfigDef;
+import org.apache.kafka.common.config.SslConfigs;
+import org.apache.kafka.common.config.types.Password;
+import org.apache.kafka.common.errors.SerializationException;
+import org.apache.kafka.common.security.ssl.DefaultSslEngineFactory;
+import org.apache.pinot.plugin.inputformat.json.JSONRecordExtractor;
+import org.apache.pinot.spi.data.readers.GenericRow;
+import org.apache.pinot.spi.data.readers.RecordExtractor;
+import org.apache.pinot.spi.plugin.PluginManager;
+import org.apache.pinot.spi.stream.StreamMessageDecoder;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static com.google.common.base.Preconditions.checkState;
+
+
+/**
+ * Decodes avro messages with confluent schema registry.
+ * First byte is MAGIC = 0, second 4 bytes are the schema id, the remainder is the value.
+ * NOTE: Do not use schema in the implementation, as schema will be removed from the params
+ */
+public class KafkaConfluentSchemaRegistryJsonMessageDecoder implements StreamMessageDecoder<byte[]> {
Review Comment:
Can we also add an accompanying test? Similar to the one for `proto`?
##########
pinot-plugins/pinot-input-format/pinot-confluent-json/src/main/java/org/apache/pinot/plugin/inputformat/json/confluent/KafkaConfluentSchemaRegistryJsonMessageDecoder.java:
##########
@@ -0,0 +1,153 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.plugin.inputformat.json.confluent;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.base.Preconditions;
+import io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient;
+import io.confluent.kafka.schemaregistry.client.SchemaRegistryClient;
+import io.confluent.kafka.schemaregistry.client.rest.RestService;
+import io.confluent.kafka.schemaregistry.json.JsonSchemaProvider;
+import io.confluent.kafka.serializers.json.KafkaJsonSchemaDeserializer;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import org.apache.kafka.common.config.ConfigDef;
+import org.apache.kafka.common.config.SslConfigs;
+import org.apache.kafka.common.config.types.Password;
+import org.apache.kafka.common.errors.SerializationException;
+import org.apache.kafka.common.security.ssl.DefaultSslEngineFactory;
+import org.apache.pinot.plugin.inputformat.json.JSONRecordExtractor;
+import org.apache.pinot.spi.data.readers.GenericRow;
+import org.apache.pinot.spi.data.readers.RecordExtractor;
+import org.apache.pinot.spi.plugin.PluginManager;
+import org.apache.pinot.spi.stream.StreamMessageDecoder;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static com.google.common.base.Preconditions.checkState;
+
+
+/**
+ * Decodes avro messages with confluent schema registry.
+ * First byte is MAGIC = 0, second 4 bytes are the schema id, the remainder is the value.
+ * NOTE: Do not use schema in the implementation, as schema will be removed from the params
+ */
+public class KafkaConfluentSchemaRegistryJsonMessageDecoder implements StreamMessageDecoder<byte[]> {
+ private static final Logger LOGGER = LoggerFactory.getLogger(KafkaConfluentSchemaRegistryJsonMessageDecoder.class);
+ private static final String SCHEMA_REGISTRY_REST_URL = "schema.registry.rest.url";
+ private static final String SCHEMA_REGISTRY_OPTS_PREFIX = "schema.registry.";
+ public static final String CACHED_SCHEMA_MAP_CAPACITY = "cached.schema.map.capacity";
+ public static final String DEFAULT_CACHED_SCHEMA_MAP_CAPACITY = "1000";
+ private KafkaJsonSchemaDeserializer _deserializer;
+ private RecordExtractor<Map<String, Object>> _jsonRecordExtractor;
+ private String _topicName;
+
+ public RestService createRestService(String schemaRegistryUrl, Map<String, String> configs) {
+ RestService restService = new RestService(schemaRegistryUrl);
+
+ ConfigDef configDef = new ConfigDef();
+ SslConfigs.addClientSslSupport(configDef);
+ Map<String, ConfigDef.ConfigKey> configKeyMap = configDef.configKeys();
+ Map<String, Object> sslConfigs = new HashMap<>();
+ for (String key : configs.keySet()) {
+ if (!key.equals(SCHEMA_REGISTRY_REST_URL) && key.startsWith(SCHEMA_REGISTRY_OPTS_PREFIX)) {
+ String value = configs.get(key);
+ String schemaRegistryOptKey = key.substring(SCHEMA_REGISTRY_OPTS_PREFIX.length());
+
+ if (configKeyMap.containsKey(schemaRegistryOptKey)) {
+ if (configKeyMap.get(schemaRegistryOptKey).type == ConfigDef.Type.PASSWORD) {
+ sslConfigs.put(schemaRegistryOptKey, new Password(value));
+ } else {
+ sslConfigs.put(schemaRegistryOptKey, value);
+ }
+ }
+ }
+ }
+
+ if (!sslConfigs.isEmpty()) {
+ DefaultSslEngineFactory sslFactory = new DefaultSslEngineFactory();
+ sslFactory.configure(sslConfigs);
+ restService.setSslSocketFactory(sslFactory.sslContext().getSocketFactory());
+ }
+ return restService;
+ }
+
+ @Override
+ public void init(Map<String, String> props, Set<String> fieldsToRead, String topicName)
+ throws Exception {
+ checkState(props.containsKey(SCHEMA_REGISTRY_REST_URL), "Missing required property '%s'", SCHEMA_REGISTRY_REST_URL);
+ String schemaRegistryUrl = props.get(SCHEMA_REGISTRY_REST_URL);
+ JsonSchemaProvider jsonSchemaProvider = new JsonSchemaProvider();
+ int identityMapCapacity = Integer.parseInt(
+ props.getOrDefault(CACHED_SCHEMA_MAP_CAPACITY, DEFAULT_CACHED_SCHEMA_MAP_CAPACITY));
+ SchemaRegistryClient schemaRegistryClient =
+ new CachedSchemaRegistryClient(createRestService(schemaRegistryUrl, props), identityMapCapacity,
+ Collections.singletonList(jsonSchemaProvider), props, null);
+
+ _deserializer = new KafkaJsonSchemaDeserializer(schemaRegistryClient);
+ Preconditions.checkNotNull(topicName, "Topic must be provided");
+ _topicName = topicName;
+ _jsonRecordExtractor = PluginManager.get().createInstance(JSONRecordExtractor.class.getName());
+ _jsonRecordExtractor.init(fieldsToRead, null);
+ }
+
+ @Override
+ public GenericRow decode(byte[] payload, GenericRow destination) {
+ try {
+ JsonNode jsonRecord = (JsonNode) _deserializer.deserialize(_topicName, payload);
+ Map<String, Object> from = JsonUtils.jsonNodeToMap(jsonRecord);
+ return _jsonRecordExtractor.extract(from, destination);
+ } catch (RuntimeException e) {
+ ignoreOrRethrowException(e);
+ return null;
+ } catch (Exception e) {
+ LOGGER.error("Caught exception while decoding row, discarding row. Payload is {}", new String(payload), e);
+ return null;
+ }
Review Comment:
The other two handlers seem to propagate the exception upwards and not handle it in a generic exception block like this. Should we keep the behavior consistent for all three decoders?
--
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: commits-unsubscribe@pinot.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org