Skip to content

Commit

Permalink
deps: removed trino-plugin-toolkit
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Ruaux committed Jun 30, 2022
1 parent 74d4eda commit 1d7aa6c
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 48 deletions.
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ injectVersion=1
jacksonVersion=2.13.1
jnaVersion=5.10.0
jodaVersion=2.10.13
junitVersion=5.8.2
lettucemodVersion=2.19.3
testcontainersRedisVersion=1.5.5
servletVersion=4.0.1
Expand Down
39 changes: 1 addition & 38 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,5 @@ projects {
}

enforce {
rule(enforcer.rules.ForceDependencies) { r ->
r.dependencies.addAll "com.google.guava:guava:$guavaVersion",
"com.google.inject:guice:$guiceVersion",
"com.google.errorprone:error_prone_annotations:$errorproneVersion",
"io.airlift:units:$unitsVersion",
"io.airlift:bootstrap:$airliftVersion",
"io.airlift:configuration:$airliftVersion",
"io.airlift:json:$airliftVersion",
"io.airlift:concurrent:$airliftVersion",
"io.airlift:log:$airliftVersion",
"io.airlift:slice:$sliceVersion",
"io.airlift:discovery:$airliftVersion",
"io.airlift:event:$airliftVersion",
"io.airlift:http-client:$airliftVersion",
"io.airlift:http-server:$airliftVersion",
"io.airlift:jaxrs:$airliftVersion",
"io.airlift:jmx:$airliftVersion",
"io.airlift:node:$airliftVersion",
"io.airlift:trace-token:$airliftVersion",
"javax.servlet:javax.servlet-api:$servletVersion",
"org.slf4j:slf4j-api:$slf4jVersion",
"com.fasterxml.jackson.core:jackson-annotations:$jacksonVersion",
"com.fasterxml.jackson.core:jackson-core:$jacksonVersion",
"com.fasterxml.jackson.core:jackson-databind:$jacksonVersion",
"com.fasterxml.jackson.dataformat:jackson-dataformat-smile:$jacksonVersion",
"javax.validation:validation-api:$validationVersion",
"javax.annotation:javax.annotation-api:$annotationVersion",
"joda-time:joda-time:$jodaVersion",
"org.awaitility:awaitility:$awaitilityVersion",
"org.antlr:antlr4-runtime:$antlrVersion",
"it.unimi.dsi:fastutil:$fastutilVersion",
"net.java.dev.jna:jna:$jnaVersion",
"javax.ws.rs:javax.ws.rs-api:$wsVersion"
}
rule(enforcer.rules.BanDuplicateClasses) { r ->
// ignore all classes under the following package
r.ignore('org.hamcrest.*')
}
enabled = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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 com.redis.trino;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonFactoryBuilder;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.airlift.json.ObjectMapperProvider;
import io.airlift.slice.DynamicSliceOutput;
import io.airlift.slice.Slice;
import io.airlift.slice.SliceOutput;
import io.airlift.slice.Slices;
import io.trino.spi.TrinoException;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;

import static com.fasterxml.jackson.core.JsonFactory.Feature.CANONICALIZE_FIELD_NAMES;
import static com.fasterxml.jackson.databind.SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS;
import static com.google.common.base.Preconditions.checkState;
import static io.trino.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT;
import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.UTF_8;

public final class JsonTypeUtil
{
private static final JsonFactory JSON_FACTORY = new JsonFactoryBuilder().disable(CANONICALIZE_FIELD_NAMES).build();
private static final ObjectMapper SORTED_MAPPER = new ObjectMapperProvider().get().configure(ORDER_MAP_ENTRIES_BY_KEYS, true);

private JsonTypeUtil() {}

// TODO: this should be available from the engine
public static Slice jsonParse(Slice slice)
{
// cast(json_parse(x) AS t)` will be optimized into `$internal$json_string_to_array/map/row_cast` in ExpressionOptimizer
// If you make changes to this function (e.g. use parse JSON string into some internal representation),
// make sure `$internal$json_string_to_array/map/row_cast` is changed accordingly.
try (JsonParser parser = createJsonParser(JSON_FACTORY, slice)) {
SliceOutput output = new DynamicSliceOutput(slice.length());
SORTED_MAPPER.writeValue((OutputStream) output, SORTED_MAPPER.readValue(parser, Object.class));
// At this point, the end of input should be reached. nextToken() has three possible results:
// - null, if the end of the input was reached
// - token, if a correct JSON token is found (e.g. '{', 'null', '1')
// - exception, if there are characters which do not form a valid JSON token (e.g. 'abc')
checkState(parser.nextToken() == null, "Found characters after the expected end of input");
return output.slice();
}
catch (IOException | RuntimeException e) {
throw new TrinoException(INVALID_FUNCTION_ARGUMENT, format("Cannot convert value to JSON: '%s'", slice.toStringUtf8()), e);
}
}

public static Slice toJsonValue(Object value)
throws IOException
{
return Slices.wrappedBuffer(SORTED_MAPPER.writeValueAsBytes(value));
}

private static JsonParser createJsonParser(JsonFactory factory, Slice json)
throws IOException
{
// Jackson tries to detect the character encoding automatically when
// using InputStream, so we pass an InputStreamReader instead.
return factory.createParser(new InputStreamReader(json.getInput(), UTF_8));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.redis.trino;

import static io.airlift.slice.Slices.utf8Slice;
import static io.trino.plugin.base.util.JsonTypeUtil.jsonParse;
import static io.trino.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR;
import static io.trino.spi.type.BigintType.BIGINT;
import static io.trino.spi.type.Chars.truncateToLengthAndTrimSpaces;
Expand Down Expand Up @@ -92,7 +91,7 @@ private void writeSlice(BlockBuilder output, Type type, String value) {
} else if (type instanceof DecimalType) {
type.writeObject(output, encodeScaledValue(new BigDecimal(value), ((DecimalType) type).getScale()));
} else if (type.getBaseName().equals(JSON)) {
type.writeSlice(output, jsonParse(utf8Slice(value)));
type.writeSlice(output, JsonTypeUtil.jsonParse(utf8Slice(value)));
} else {
throw new TrinoException(GENERIC_INTERNAL_ERROR, "Unhandled type for Slice: " + type.getTypeSignature());
}
Expand Down
10 changes: 2 additions & 8 deletions subprojects/trino-redisearch/trino-redisearch.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,16 @@ plugins {

dependencies {
compileOnly group: 'io.trino', name: 'trino-spi', version: trinoVersion
implementation group: 'io.trino', name: 'trino-plugin-toolkit', version: trinoVersion
implementation group: 'io.airlift', name: 'bootstrap', version: airliftVersion
implementation group: 'io.airlift', name: 'configuration', version: airliftVersion
implementation group: 'io.airlift', name: 'json', version: airliftVersion
implementation group: 'com.redis', name: 'lettucemod', version: lettucemodVersion
implementation group: 'com.github.f4b6a3', name: 'ulid-creator', version: ulidVersion
implementation group: 'javax.validation', name: 'validation-api', version: validationVersion
testImplementation group: 'com.redis.testcontainers', name: 'testcontainers-redis-junit', version: testcontainersRedisVersion
testImplementation group: 'com.redis', name: 'lettucemod', version: lettucemodVersion, classifier: 'tests'
testImplementation(group: 'com.redis.testcontainers', name: 'testcontainers-redis-junit', version: testcontainersRedisVersion) {
exclude group: 'com.redis', module: 'lettucemod'
exclude group: 'org.junit.jupiter', module: 'junit-jupiter-api'
}
testImplementation group: 'io.airlift', name: 'testing', version: airliftVersion
testImplementation(group: 'io.trino', name: 'trino-testing', version: trinoVersion) {
exclude group: 'org.testcontainers', module: 'testcontainers-java'
}
}
}

test {
Expand Down

0 comments on commit 1d7aa6c

Please sign in to comment.