Skip to content

Commit 470b674

Browse files
authored
[feat][sql] Bump Trino version to 368 and fix Decimal breaking change (#20016)
Signed-off-by: tison <wander4096@gmail.com>
1 parent 90b9dd4 commit 470b674

10 files changed

Lines changed: 145 additions & 102 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ flexible messaging model and an intuitive client API.</description>
184184
<json-smart.version>2.4.10</json-smart.version>
185185
<opensearch.version>1.2.4</opensearch.version>
186186
<elasticsearch-java.version>8.5.2</elasticsearch-java.version>
187-
<trino.version>363</trino.version>
187+
<trino.version>368</trino.version>
188188
<debezium.version>1.9.7.Final</debezium.version>
189189
<debezium.postgresql.version>42.5.0</debezium.postgresql.version>
190190
<debezium.mysql.version>8.0.30</debezium.mysql.version>

pulsar-sql/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<okhttp3.version>3.14.9</okhttp3.version>
3737
<!-- use okio version that matches the okhttp3 version -->
3838
<okio.version>1.17.2</okio.version>
39-
<airlift.version>208</airlift.version>
39+
<airlift.version>213</airlift.version>
4040
</properties>
4141

4242
<dependencyManagement>

pulsar-sql/presto-distribution/LICENSE

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -303,28 +303,28 @@ The Apache Software License, Version 2.0
303303
- bytecode-1.2.jar
304304
* Airlift
305305
- aircompressor-0.20.jar
306-
- bootstrap-208.jar
307-
- concurrent-208.jar
308-
- configuration-208.jar
309-
- discovery-208.jar
306+
- bootstrap-213.jar
307+
- concurrent-213.jar
308+
- configuration-213.jar
309+
- discovery-213.jar
310310
- discovery-server-1.30.jar
311-
- event-208.jar
312-
- event-http-208.jar
313-
- http-client-208.jar
314-
- http-server-208.jar
315-
- jmx-208.jar
316-
- jmx-http-208.jar
317-
- jmx-http-rpc-208.jar
311+
- event-213.jar
312+
- event-http-213.jar
313+
- http-client-213.jar
314+
- http-server-213.jar
315+
- jmx-213.jar
316+
- jmx-http-213.jar
317+
- jmx-http-rpc-213.jar
318318
- joni-2.1.5.3.jar
319-
- json-208.jar
320-
- log-208.jar
321-
- log-manager-208.jar
322-
- node-208.jar
319+
- json-213.jar
320+
- log-213.jar
321+
- log-manager-213.jar
322+
- node-213.jar
323323
- parameternames-1.4.jar
324-
- security-208.jar
325-
- slice-0.39.jar
326-
- stats-208.jar
327-
- trace-token-208.jar
324+
- security-213.jar
325+
- slice-0.41.jar
326+
- stats-213.jar
327+
- trace-token-213.jar
328328
- units-1.6.jar
329329
* Apache HTTP Client
330330
- httpclient-4.5.13.jar
@@ -340,7 +340,9 @@ The Apache Software License, Version 2.0
340340
* J2ObjC Annotations
341341
- j2objc-annotations-1.3.jar
342342
* JSON Web Token Support For The JVM
343-
- jjwt-0.9.0.jar
343+
- jjwt-api-0.11.1.jar
344+
- jjwt-impl-0.11.1.jar
345+
- jjwt-jackson-0.11.1.jar
344346
* Jmxutils
345347
- jmxutils-1.21.jar
346348
* LevelDB
@@ -384,18 +386,18 @@ The Apache Software License, Version 2.0
384386
* Okio
385387
- okio-1.17.2.jar
386388
* Trino
387-
- trino-array-363.jar
388-
- trino-cli-363.jar
389-
- trino-client-363.jar
390-
- trino-geospatial-toolkit-363.jar
391-
- trino-main-363.jar
392-
- trino-matching-363.jar
393-
- trino-memory-context-363.jar
394-
- trino-parser-363.jar
395-
- trino-plugin-toolkit-363.jar
396-
- trino-server-main-363.jar
397-
- trino-spi-363.jar
398-
- trino-record-decoder-363.jar
389+
- trino-array-368.jar
390+
- trino-cli-368.jar
391+
- trino-client-368.jar
392+
- trino-geospatial-toolkit-368.jar
393+
- trino-main-368.jar
394+
- trino-matching-368.jar
395+
- trino-memory-context-368.jar
396+
- trino-parser-368.jar
397+
- trino-plugin-toolkit-368.jar
398+
- trino-server-main-368.jar
399+
- trino-spi-368.jar
400+
- trino-record-decoder-368.jar
399401
* RocksDB JNI
400402
- rocksdbjni-6.29.4.1.jar
401403
* SnakeYAML
@@ -456,6 +458,7 @@ The Apache Software License, Version 2.0
456458
- javassist-3.25.0-GA.jar
457459
* Java Native Access
458460
- jna-5.12.1.jar
461+
- jna-platform-5.10.0.jar
459462
* Java Object Layout: Core
460463
- jol-core-0.2.jar
461464
* Yahoo Datasketches
@@ -493,7 +496,7 @@ BSD License
493496
* ANTLR 4 Runtime
494497
- antlr4-runtime-4.9.2.jar
495498
* ASM, a very small and fast Java bytecode manipulation framework
496-
- asm-6.2.1.jar
499+
- asm-9.1.jar
497500
- asm-analysis-6.2.1.jar
498501
- asm-tree-6.2.1.jar
499502
- asm-util-6.2.1.jar
@@ -518,6 +521,8 @@ MIT License
518521
* ScribeJava
519522
- scribejava-apis-6.9.0.jar
520523
- scribejava-core-6.9.0.jar
524+
* OSHI
525+
- oshi-core-5.8.5.jar
521526

522527
CDDL - 1.0
523528
* OSGi Resource Locator
@@ -533,16 +538,16 @@ CDDL-1.1 -- licenses/LICENSE-CDDL-1.1.txt
533538
- hk2-utils-2.6.1.jar
534539
- aopalliance-repackaged-2.6.1.jar
535540
* Jersey
536-
- jaxrs-208.jar
541+
- jaxrs-213.jar
537542
- jersey-client-2.34.jar
543+
- jersey-common-2.34.jar
538544
- jersey-container-servlet-2.34.jar
539545
- jersey-container-servlet-core-2.34.jar
540546
- jersey-entity-filtering-2.34.jar
541547
- jersey-hk2-2.34.jar
542548
- jersey-media-json-jackson-2.34.jar
543549
- jersey-media-multipart-2.34.jar
544550
- jersey-server-2.34.jar
545-
- jersey-common-2.34.jar
546551
* JAXB
547552
- jaxb-api-2.3.1.jar
548553
- jaxb-runtime-2.3.4.jar

pulsar-sql/presto-distribution/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@
9797
<groupId>com.google.inject.extensions</groupId>
9898
<artifactId>guice-multibindings</artifactId>
9999
</exclusion>
100+
<exclusion>
101+
<groupId>org.apache.logging.log4j</groupId>
102+
<artifactId>log4j-to-slf4j</artifactId>
103+
</exclusion>
100104
</exclusions>
101105
</dependency>
102106

pulsar-sql/presto-pulsar/pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@
4141
<dependency>
4242
<groupId>io.airlift</groupId>
4343
<artifactId>bootstrap</artifactId>
44+
<exclusions>
45+
<exclusion>
46+
<groupId>org.apache.logging.log4j</groupId>
47+
<artifactId>log4j-to-slf4j</artifactId>
48+
</exclusion>
49+
</exclusions>
4450
</dependency>
45-
4651
<dependency>
4752
<groupId>io.airlift</groupId>
4853
<artifactId>json</artifactId>

pulsar-sql/presto-pulsar/src/main/java/org/apache/pulsar/sql/presto/decoder/avro/PulsarAvroColumnDecoder.java

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
import io.trino.spi.type.BooleanType;
4242
import io.trino.spi.type.DateType;
4343
import io.trino.spi.type.DecimalType;
44-
import io.trino.spi.type.Decimals;
4544
import io.trino.spi.type.DoubleType;
45+
import io.trino.spi.type.Int128;
4646
import io.trino.spi.type.IntegerType;
4747
import io.trino.spi.type.MapType;
4848
import io.trino.spi.type.RealType;
@@ -66,11 +66,14 @@
6666
import org.apache.avro.generic.GenericRecord;
6767

6868
/**
69-
* Copy from {@link io.trino.decoder.avro.AvroColumnDecoder} (presto-record-decoder-345)
70-
* with A little bit pulsar's extensions.
71-
* 1) support {@link io.trino.spi.type.TimestampType},{@link io.trino.spi.type.DateType}DATE,
72-
* * {@link io.trino.spi.type.TimeType}.
69+
* Copy from {@link io.trino.decoder.avro.AvroColumnDecoder}
70+
* with A little pulsar's extensions.
71+
* 1) support date and time types.
72+
* {@link io.trino.spi.type.TimestampType}
73+
* {@link io.trino.spi.type.DateType}
74+
* {@link io.trino.spi.type.TimeType}
7375
* 2) support {@link io.trino.spi.type.RealType}.
76+
* 3) support {@link io.trino.spi.type.DecimalType}.
7477
*/
7578
public class PulsarAvroColumnDecoder {
7679
private static final Set<Type> SUPPORTED_PRIMITIVE_TYPES = ImmutableSet.of(
@@ -252,13 +255,6 @@ private static Slice getSlice(Object value, Type type, String columnName) {
252255
}
253256
}
254257

255-
// The returned Slice size must be equals to 18 Byte
256-
if (type instanceof DecimalType) {
257-
ByteBuffer buffer = (ByteBuffer) value;
258-
BigInteger bigInteger = new BigInteger(buffer.array());
259-
return Decimals.encodeUnscaledValue(bigInteger);
260-
}
261-
262258
throw new TrinoException(DECODER_CONVERSION_NOT_SUPPORTED,
263259
format("cannot decode object of '%s' as '%s' for column '%s'",
264260
value.getClass(), type, columnName));
@@ -274,6 +270,9 @@ private static Block serializeObject(BlockBuilder builder, Object value, Type ty
274270
if (type instanceof RowType) {
275271
return serializeRow(builder, value, type, columnName);
276272
}
273+
if (type instanceof DecimalType && !((DecimalType) type).isShort()) {
274+
return serializeLongDecimal(builder, value, type, columnName);
275+
}
277276
serializePrimitive(builder, value, type, columnName);
278277
return null;
279278
}
@@ -299,6 +298,22 @@ private static Block serializeList(BlockBuilder parentBlockBuilder, Object value
299298
return blockBuilder.build();
300299
}
301300

301+
private static Block serializeLongDecimal(
302+
BlockBuilder parentBlockBuilder, Object value, Type type, String columnName) {
303+
final BlockBuilder blockBuilder;
304+
if (parentBlockBuilder != null) {
305+
blockBuilder = parentBlockBuilder;
306+
} else {
307+
blockBuilder = type.createBlockBuilder(null, 1);
308+
}
309+
final ByteBuffer buffer = (ByteBuffer) value;
310+
type.writeObject(blockBuilder, Int128.fromBigEndian(buffer.array()));
311+
if (parentBlockBuilder == null) {
312+
return blockBuilder.getSingleValueBlock(0);
313+
}
314+
return null;
315+
}
316+
302317
private static void serializePrimitive(BlockBuilder blockBuilder, Object value, Type type, String columnName) {
303318
requireNonNull(blockBuilder, "parent blockBuilder is null");
304319

pulsar-sql/presto-pulsar/src/main/java/org/apache/pulsar/sql/presto/decoder/json/PulsarJsonFieldDecoder.java

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import static java.util.Objects.requireNonNull;
3030
import com.fasterxml.jackson.databind.JsonNode;
3131
import com.fasterxml.jackson.databind.node.ArrayNode;
32+
import com.fasterxml.jackson.databind.node.DecimalNode;
3233
import com.fasterxml.jackson.databind.node.ObjectNode;
3334
import com.google.common.collect.ImmutableList;
3435
import io.airlift.log.Logger;
@@ -45,8 +46,8 @@
4546
import io.trino.spi.type.BooleanType;
4647
import io.trino.spi.type.DateType;
4748
import io.trino.spi.type.DecimalType;
48-
import io.trino.spi.type.Decimals;
4949
import io.trino.spi.type.DoubleType;
50+
import io.trino.spi.type.Int128;
5051
import io.trino.spi.type.IntegerType;
5152
import io.trino.spi.type.MapType;
5253
import io.trino.spi.type.RealType;
@@ -59,21 +60,22 @@
5960
import io.trino.spi.type.Type;
6061
import io.trino.spi.type.VarbinaryType;
6162
import io.trino.spi.type.VarcharType;
62-
import java.math.BigInteger;
6363
import java.util.Iterator;
6464
import java.util.List;
6565
import java.util.Map;
6666
import org.apache.commons.lang3.tuple.Pair;
6767

6868
/**
69-
* Copy from {@link io.trino.decoder.json.DefaultJsonFieldDecoder} (presto-record-decoder-345)
70-
* with some pulsar's extensions.
69+
* Copy from {@link io.trino.decoder.json.DefaultJsonFieldDecoder} with some pulsar's extensions.
7170
* 1) support {@link io.trino.spi.type.ArrayType}.
7271
* 2) support {@link io.trino.spi.type.MapType}.
7372
* 3) support {@link io.trino.spi.type.RowType}.
74-
* 4) support {@link io.trino.spi.type.TimestampType},{@link io.trino.spi.type.DateType},
75-
* {@link io.trino.spi.type.TimeType}.
73+
* 4) support date and time types.
74+
* {@link io.trino.spi.type.TimestampType}
75+
* {@link io.trino.spi.type.DateType}
76+
* {@link io.trino.spi.type.TimeType}
7677
* 5) support {@link io.trino.spi.type.RealType}.
78+
* 6) support {@link io.trino.spi.type.DecimalType}.
7779
*/
7880
public class PulsarJsonFieldDecoder
7981
implements JsonFieldDecoder {
@@ -90,7 +92,6 @@ public PulsarJsonFieldDecoder(DecoderColumnHandle columnHandle) {
9092
Pair<Long, Long> range = getNumRangeByType(columnHandle.getType());
9193
minValue = range.getKey();
9294
maxValue = range.getValue();
93-
9495
}
9596

9697
private static Pair<Long, Long> getNumRangeByType(Type type) {
@@ -221,7 +222,7 @@ public static long getLong(JsonNode value, Type type, String columnName, long mi
221222
}
222223

223224
// If it is decimalType, need to eliminate the decimal point,
224-
// and give it to presto to set the decimal point
225+
// and give it to trino to set the decimal point
225226
if (type instanceof DecimalType) {
226227
String decimalLong = value.asText().replace(".", "");
227228
return Long.parseLong(decimalLong);
@@ -273,14 +274,6 @@ public static double getDouble(JsonNode value, Type type, String columnName) {
273274
private static Slice getSlice(JsonNode value, Type type, String columnName) {
274275
String textValue = value.isValueNode() ? value.asText() : value.toString();
275276

276-
// If it is decimalType, need to eliminate the decimal point,
277-
// and give it to presto to set the decimal point
278-
if (type instanceof DecimalType) {
279-
textValue = textValue.replace(".", "");
280-
BigInteger bigInteger = new BigInteger(textValue);
281-
return Decimals.encodeUnscaledValue(bigInteger);
282-
}
283-
284277
Slice slice = utf8Slice(textValue);
285278
if (type instanceof VarcharType) {
286279
slice = truncateToLength(slice, type);
@@ -298,6 +291,9 @@ private Block serializeObject(BlockBuilder builder, Object value, Type type, Str
298291
if (type instanceof RowType) {
299292
return serializeRow(builder, value, type, columnName);
300293
}
294+
if (type instanceof DecimalType && !((DecimalType) type).isShort()) {
295+
return serializeLongDecimal(builder, value, type, columnName);
296+
}
301297
serializePrimitive(builder, value, type, columnName);
302298
return null;
303299
}
@@ -330,6 +326,27 @@ private Block serializeList(BlockBuilder parentBlockBuilder, Object value, Type
330326
return blockBuilder.build();
331327
}
332328

329+
private static Block serializeLongDecimal(
330+
BlockBuilder parentBlockBuilder, Object value, Type type, String columnName) {
331+
final BlockBuilder blockBuilder;
332+
if (parentBlockBuilder != null) {
333+
blockBuilder = parentBlockBuilder;
334+
} else {
335+
blockBuilder = type.createBlockBuilder(null, 1);
336+
}
337+
338+
assert value instanceof DecimalNode;
339+
final DecimalNode node = (DecimalNode) value;
340+
// For decimalType, need to eliminate the decimal point,
341+
// and give it to trino to set the decimal point
342+
type.writeObject(blockBuilder, Int128.valueOf(node.asText().replace(".", "")));
343+
344+
if (parentBlockBuilder == null) {
345+
return blockBuilder.getSingleValueBlock(0);
346+
}
347+
return null;
348+
}
349+
333350
private void serializePrimitive(BlockBuilder blockBuilder, Object node, Type type, String columnName) {
334351
requireNonNull(blockBuilder, "parent blockBuilder is null");
335352

0 commit comments

Comments
 (0)