Skip to content

Commit 1d7aa6c

Browse files
author
Julien Ruaux
committed
deps: removed trino-plugin-toolkit
1 parent 74d4eda commit 1d7aa6c

File tree

5 files changed

+84
-48
lines changed

5 files changed

+84
-48
lines changed

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ injectVersion=1
1616
jacksonVersion=2.13.1
1717
jnaVersion=5.10.0
1818
jodaVersion=2.10.13
19+
junitVersion=5.8.2
1920
lettucemodVersion=2.19.3
2021
testcontainersRedisVersion=1.5.5
2122
servletVersion=4.0.1

settings.gradle

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -33,42 +33,5 @@ projects {
3333
}
3434

3535
enforce {
36-
rule(enforcer.rules.ForceDependencies) { r ->
37-
r.dependencies.addAll "com.google.guava:guava:$guavaVersion",
38-
"com.google.inject:guice:$guiceVersion",
39-
"com.google.errorprone:error_prone_annotations:$errorproneVersion",
40-
"io.airlift:units:$unitsVersion",
41-
"io.airlift:bootstrap:$airliftVersion",
42-
"io.airlift:configuration:$airliftVersion",
43-
"io.airlift:json:$airliftVersion",
44-
"io.airlift:concurrent:$airliftVersion",
45-
"io.airlift:log:$airliftVersion",
46-
"io.airlift:slice:$sliceVersion",
47-
"io.airlift:discovery:$airliftVersion",
48-
"io.airlift:event:$airliftVersion",
49-
"io.airlift:http-client:$airliftVersion",
50-
"io.airlift:http-server:$airliftVersion",
51-
"io.airlift:jaxrs:$airliftVersion",
52-
"io.airlift:jmx:$airliftVersion",
53-
"io.airlift:node:$airliftVersion",
54-
"io.airlift:trace-token:$airliftVersion",
55-
"javax.servlet:javax.servlet-api:$servletVersion",
56-
"org.slf4j:slf4j-api:$slf4jVersion",
57-
"com.fasterxml.jackson.core:jackson-annotations:$jacksonVersion",
58-
"com.fasterxml.jackson.core:jackson-core:$jacksonVersion",
59-
"com.fasterxml.jackson.core:jackson-databind:$jacksonVersion",
60-
"com.fasterxml.jackson.dataformat:jackson-dataformat-smile:$jacksonVersion",
61-
"javax.validation:validation-api:$validationVersion",
62-
"javax.annotation:javax.annotation-api:$annotationVersion",
63-
"joda-time:joda-time:$jodaVersion",
64-
"org.awaitility:awaitility:$awaitilityVersion",
65-
"org.antlr:antlr4-runtime:$antlrVersion",
66-
"it.unimi.dsi:fastutil:$fastutilVersion",
67-
"net.java.dev.jna:jna:$jnaVersion",
68-
"javax.ws.rs:javax.ws.rs-api:$wsVersion"
69-
}
70-
rule(enforcer.rules.BanDuplicateClasses) { r ->
71-
// ignore all classes under the following package
72-
r.ignore('org.hamcrest.*')
73-
}
36+
enabled = false
7437
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.redis.trino;
15+
16+
import com.fasterxml.jackson.core.JsonFactory;
17+
import com.fasterxml.jackson.core.JsonFactoryBuilder;
18+
import com.fasterxml.jackson.core.JsonParser;
19+
import com.fasterxml.jackson.databind.ObjectMapper;
20+
import io.airlift.json.ObjectMapperProvider;
21+
import io.airlift.slice.DynamicSliceOutput;
22+
import io.airlift.slice.Slice;
23+
import io.airlift.slice.SliceOutput;
24+
import io.airlift.slice.Slices;
25+
import io.trino.spi.TrinoException;
26+
27+
import java.io.IOException;
28+
import java.io.InputStreamReader;
29+
import java.io.OutputStream;
30+
31+
import static com.fasterxml.jackson.core.JsonFactory.Feature.CANONICALIZE_FIELD_NAMES;
32+
import static com.fasterxml.jackson.databind.SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS;
33+
import static com.google.common.base.Preconditions.checkState;
34+
import static io.trino.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT;
35+
import static java.lang.String.format;
36+
import static java.nio.charset.StandardCharsets.UTF_8;
37+
38+
public final class JsonTypeUtil
39+
{
40+
private static final JsonFactory JSON_FACTORY = new JsonFactoryBuilder().disable(CANONICALIZE_FIELD_NAMES).build();
41+
private static final ObjectMapper SORTED_MAPPER = new ObjectMapperProvider().get().configure(ORDER_MAP_ENTRIES_BY_KEYS, true);
42+
43+
private JsonTypeUtil() {}
44+
45+
// TODO: this should be available from the engine
46+
public static Slice jsonParse(Slice slice)
47+
{
48+
// cast(json_parse(x) AS t)` will be optimized into `$internal$json_string_to_array/map/row_cast` in ExpressionOptimizer
49+
// If you make changes to this function (e.g. use parse JSON string into some internal representation),
50+
// make sure `$internal$json_string_to_array/map/row_cast` is changed accordingly.
51+
try (JsonParser parser = createJsonParser(JSON_FACTORY, slice)) {
52+
SliceOutput output = new DynamicSliceOutput(slice.length());
53+
SORTED_MAPPER.writeValue((OutputStream) output, SORTED_MAPPER.readValue(parser, Object.class));
54+
// At this point, the end of input should be reached. nextToken() has three possible results:
55+
// - null, if the end of the input was reached
56+
// - token, if a correct JSON token is found (e.g. '{', 'null', '1')
57+
// - exception, if there are characters which do not form a valid JSON token (e.g. 'abc')
58+
checkState(parser.nextToken() == null, "Found characters after the expected end of input");
59+
return output.slice();
60+
}
61+
catch (IOException | RuntimeException e) {
62+
throw new TrinoException(INVALID_FUNCTION_ARGUMENT, format("Cannot convert value to JSON: '%s'", slice.toStringUtf8()), e);
63+
}
64+
}
65+
66+
public static Slice toJsonValue(Object value)
67+
throws IOException
68+
{
69+
return Slices.wrappedBuffer(SORTED_MAPPER.writeValueAsBytes(value));
70+
}
71+
72+
private static JsonParser createJsonParser(JsonFactory factory, Slice json)
73+
throws IOException
74+
{
75+
// Jackson tries to detect the character encoding automatically when
76+
// using InputStream, so we pass an InputStreamReader instead.
77+
return factory.createParser(new InputStreamReader(json.getInput(), UTF_8));
78+
}
79+
}

subprojects/trino-redisearch/src/main/java/com/redis/trino/RediSearchPageSourceResultWriter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.redis.trino;
22

33
import static io.airlift.slice.Slices.utf8Slice;
4-
import static io.trino.plugin.base.util.JsonTypeUtil.jsonParse;
54
import static io.trino.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR;
65
import static io.trino.spi.type.BigintType.BIGINT;
76
import static io.trino.spi.type.Chars.truncateToLengthAndTrimSpaces;
@@ -92,7 +91,7 @@ private void writeSlice(BlockBuilder output, Type type, String value) {
9291
} else if (type instanceof DecimalType) {
9392
type.writeObject(output, encodeScaledValue(new BigDecimal(value), ((DecimalType) type).getScale()));
9493
} else if (type.getBaseName().equals(JSON)) {
95-
type.writeSlice(output, jsonParse(utf8Slice(value)));
94+
type.writeSlice(output, JsonTypeUtil.jsonParse(utf8Slice(value)));
9695
} else {
9796
throw new TrinoException(GENERIC_INTERNAL_ERROR, "Unhandled type for Slice: " + type.getTypeSignature());
9897
}

subprojects/trino-redisearch/trino-redisearch.gradle

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,16 @@ plugins {
44

55
dependencies {
66
compileOnly group: 'io.trino', name: 'trino-spi', version: trinoVersion
7-
implementation group: 'io.trino', name: 'trino-plugin-toolkit', version: trinoVersion
87
implementation group: 'io.airlift', name: 'bootstrap', version: airliftVersion
98
implementation group: 'io.airlift', name: 'configuration', version: airliftVersion
109
implementation group: 'io.airlift', name: 'json', version: airliftVersion
1110
implementation group: 'com.redis', name: 'lettucemod', version: lettucemodVersion
1211
implementation group: 'com.github.f4b6a3', name: 'ulid-creator', version: ulidVersion
13-
implementation group: 'javax.validation', name: 'validation-api', version: validationVersion
12+
testImplementation group: 'com.redis.testcontainers', name: 'testcontainers-redis-junit', version: testcontainersRedisVersion
1413
testImplementation group: 'com.redis', name: 'lettucemod', version: lettucemodVersion, classifier: 'tests'
15-
testImplementation(group: 'com.redis.testcontainers', name: 'testcontainers-redis-junit', version: testcontainersRedisVersion) {
16-
exclude group: 'com.redis', module: 'lettucemod'
17-
exclude group: 'org.junit.jupiter', module: 'junit-jupiter-api'
18-
}
19-
testImplementation group: 'io.airlift', name: 'testing', version: airliftVersion
2014
testImplementation(group: 'io.trino', name: 'trino-testing', version: trinoVersion) {
2115
exclude group: 'org.testcontainers', module: 'testcontainers-java'
22-
}
16+
}
2317
}
2418

2519
test {

0 commit comments

Comments
 (0)