-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JSON type support to the Pinot Connector
Pinot does not yet support filtering on json type.
- Loading branch information
1 parent
d09a786
commit 05a6295
Showing
10 changed files
with
214 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
plugin/trino-pinot/src/main/java/io/trino/plugin/pinot/decoders/JsonDecoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Licensed 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 io.trino.plugin.pinot.decoders; | ||
|
||
import io.airlift.slice.Slice; | ||
import io.trino.spi.TrinoException; | ||
import io.trino.spi.block.BlockBuilder; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import static io.airlift.slice.Slices.utf8Slice; | ||
import static io.trino.plugin.base.util.JsonTypeUtil.jsonParse; | ||
import static io.trino.spi.StandardErrorCode.TYPE_MISMATCH; | ||
import static java.lang.String.format; | ||
|
||
public class JsonDecoder | ||
implements Decoder | ||
{ | ||
@Override | ||
public void decode(Supplier<Object> getter, BlockBuilder output) | ||
{ | ||
Object value = getter.get(); | ||
if (value == null) { | ||
output.appendNull(); | ||
} | ||
else if (value instanceof String) { | ||
Slice slice = jsonParse(utf8Slice((String) value)); | ||
output.writeBytes(slice, 0, slice.length()).closeEntry(); | ||
} | ||
else { | ||
throw new TrinoException(TYPE_MISMATCH, format("Expected a json value of type STRING: %s [%s]", value, value.getClass().getSimpleName())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
plugin/trino-pinot/src/test/resources/json_offlineSpec.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"tableName": "json_table", | ||
"tableType": "OFFLINE", | ||
"segmentsConfig": { | ||
"timeColumnName": "updated_at_seconds", | ||
"retentionTimeUnit": "DAYS", | ||
"retentionTimeValue": "365", | ||
"segmentPushType": "APPEND", | ||
"segmentPushFrequency": "daily", | ||
"segmentAssignmentStrategy": "BalanceNumSegmentAssignmentStrategy", | ||
"replication": "1" | ||
}, | ||
"tenants": { | ||
"broker": "DefaultTenant", | ||
"server": "DefaultTenant" | ||
}, | ||
"tableIndexConfig": { | ||
"loadMode": "MMAP", | ||
"invertedIndexColumns": ["string_col"], | ||
"sortedColumn": ["updated_at_seconds"], | ||
"noDictionaryColumns": ["json_col"], | ||
"starTreeIndexConfigs": [], | ||
"aggregateMetrics": "true", | ||
"nullHandlingEnabled": "true" | ||
}, | ||
"metadata": { | ||
"customConfigs": { | ||
"owner": "analytics@example.com" | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
plugin/trino-pinot/src/test/resources/json_realtimeSpec.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"tableName": "json_table", | ||
"tableType": "REALTIME", | ||
"segmentsConfig": { | ||
"timeColumnName": "updated_at_seconds", | ||
"timeType": "SECONDS", | ||
"retentionTimeUnit": "DAYS", | ||
"retentionTimeValue": "365", | ||
"segmentPushType": "APPEND", | ||
"segmentPushFrequency": "daily", | ||
"segmentAssignmentStrategy": "BalanceNumSegmentAssignmentStrategy", | ||
"schemaName": "json_table", | ||
"replicasPerPartition": "1" | ||
}, | ||
"tenants": { | ||
"broker": "DefaultTenant", | ||
"server": "DefaultTenant" | ||
}, | ||
"tableIndexConfig": { | ||
"loadMode": "MMAP", | ||
"invertedIndexColumns": ["string_col"], | ||
"sortedColumn": ["updated_at_seconds"], | ||
"noDictionaryColumns": ["json_col"], | ||
"streamConfigs": { | ||
"streamType": "kafka", | ||
"stream.kafka.consumer.type": "LowLevel", | ||
"stream.kafka.topic.name": "json_table", | ||
"stream.kafka.decoder.class.name": "org.apache.pinot.plugin.inputformat.avro.confluent.KafkaConfluentSchemaRegistryAvroMessageDecoder", | ||
"stream.kafka.consumer.factory.class.name": "org.apache.pinot.plugin.stream.kafka20.KafkaConsumerFactory", | ||
"stream.kafka.decoder.prop.schema.registry.rest.url": "http://schema-registry:8081", | ||
"stream.kafka.zk.broker.url": "zookeeper:2181/", | ||
"stream.kafka.broker.list": "kafka:9092", | ||
"realtime.segment.flush.threshold.time": "1m", | ||
"realtime.segment.flush.threshold.size": "0", | ||
"realtime.segment.flush.desired.size": "1M", | ||
"isolation.level": "read_committed", | ||
"stream.kafka.consumer.prop.auto.offset.reset": "smallest", | ||
"stream.kafka.consumer.prop.group.id": "json_table" | ||
} | ||
}, | ||
"metadata": { | ||
"customConfigs": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"schemaName": "json_table", | ||
"dimensionFieldSpecs": [ | ||
{ | ||
"name": "string_col", | ||
"dataType": "STRING" | ||
}, | ||
{ | ||
"name": "json_col", | ||
"dataType": "JSON", | ||
"maxLength": 2147483647 | ||
} | ||
], | ||
"dateTimeFieldSpecs": [ | ||
{ | ||
"name": "updated_at_seconds", | ||
"dataType": "LONG", | ||
"defaultNullValue" : 0, | ||
"format": "1:SECONDS:EPOCH", | ||
"transformFunction": "toEpochSeconds(updatedAt)", | ||
"granularity" : "1:SECONDS" | ||
} | ||
] | ||
} |