From d1b882f9161552ea3194d9c3b212a3bb7347341a Mon Sep 17 00:00:00 2001 From: linghengqian Date: Wed, 22 Jan 2025 11:12:32 +0800 Subject: [PATCH] Add GraalVM Reachability Metadata and corresponding nativeTest for Presto --- .../graalvm-native-image/_index.cn.md | 3 - .../graalvm-native-image/_index.en.md | 3 - .../data/loader/PrestoMetaDataLoader.java | 114 +++++++++++ ...metadata.data.loader.DialectMetaDataLoader | 18 ++ .../database/PrestoDatabaseMetaDataTest.java | 44 +++++ .../presto-jdbc/0.290/proxy-config.json | 6 + .../presto-jdbc/0.290/reflect-config.json | 182 ++++++++++++++++++ .../presto-jdbc/0.290/resource-config.json | 29 +++ .../reflect-config.json | 80 ++++++-- .../resource-config.json | 7 +- .../reflect-config.json | 10 + .../hamcrest/3.0/reflect-config.json | 18 ++ .../junit-jupiter/5.11.1/reflect-config.json | 5 + pom.xml | 2 +- test/native/pom.xml | 11 ++ .../natived/commons/TestShardingService.java | 13 ++ .../natived/jdbc/databases/PrestoTest.java | 169 ++++++++++++++++ .../reflect-config.json | 48 +++-- .../properties/presto-config.properties | 25 +++ .../properties/presto-memory.properties | 18 ++ .../yaml/jdbc/databases/presto.yaml | 66 +++++++ 21 files changed, 827 insertions(+), 44 deletions(-) create mode 100644 infra/database/type/presto/src/main/java/org/apache/shardingsphere/infra/database/presto/metadata/data/loader/PrestoMetaDataLoader.java create mode 100644 infra/database/type/presto/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.metadata.data.loader.DialectMetaDataLoader create mode 100644 infra/database/type/presto/src/test/java/org/apache/shardingsphere/infra/database/presto/database/PrestoDatabaseMetaDataTest.java create mode 100644 infra/reachability-metadata/src/main/resources/META-INF/native-image/com.facebook.presto/presto-jdbc/0.290/proxy-config.json create mode 100644 infra/reachability-metadata/src/main/resources/META-INF/native-image/com.facebook.presto/presto-jdbc/0.290/reflect-config.json create mode 100644 infra/reachability-metadata/src/main/resources/META-INF/native-image/com.facebook.presto/presto-jdbc/0.290/resource-config.json create mode 100644 infra/reachability-metadata/src/main/resources/META-INF/native-image/org.hamcrest/hamcrest/3.0/reflect-config.json create mode 100644 test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/PrestoTest.java create mode 100644 test/native/src/test/resources/test-native/properties/presto-config.properties create mode 100644 test/native/src/test/resources/test-native/properties/presto-memory.properties create mode 100644 test/native/src/test/resources/test-native/yaml/jdbc/databases/presto.yaml diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.cn.md b/docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.cn.md index f18270218c9f5..c175314475349 100644 --- a/docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.cn.md +++ b/docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.cn.md @@ -330,9 +330,6 @@ ShardingSphere 的单元测试仅使用 Maven 模块 `io.github.linghengqian:hiv 9. 由于 https://github.com/apache/doris/issues/9426 的影响,当通过 Shardinghere JDBC 连接至 Apache Doris FE, 用户需自行提供 `apache/doris` 集成模块相关的 GraalVM Reachability Metadata。 -10. 由于 https://github.com/prestodb/presto/issues/23226 的影响,当通过 Shardinghere JDBC 连接至 Presto Server, -用户需自行提供 `com.facebook.presto:presto-jdbc` 和 `prestodb/presto` 集成模块相关的 GraalVM Reachability Metadata。 - ## 贡献 GraalVM Reachability Metadata ShardingSphere 对在 GraalVM Native Image 下的可用性的验证,是通过 GraalVM Native Build Tools 的 Maven Plugin 子项目来完成的。 diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.en.md b/docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.en.md index 8ebe31f5e4248..ac5380be022ed 100644 --- a/docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.en.md +++ b/docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.en.md @@ -344,9 +344,6 @@ the Oracle JDBC Driver corresponding to the `com.oracle.database.jdbc:ojdbc8` Ma 9. Due to https://github.com/apache/doris/issues/9426, when connecting to Apache Doris FE via Shardinghere JDBC, users need to provide GraalVM Reachability Metadata related to the `apache/doris` integration module. -10. Due to https://github.com/prestodb/presto/issues/23226, when connecting to Presto Server via Shardinghere JDBC, - users need to provide GraalVM Reachability Metadata related to the `com.facebook.presto:presto-jdbc` and `prestodb/presto` integration module. - ## Contribute GraalVM Reachability Metadata The verification of ShardingSphere's availability under GraalVM Native Image is completed through the Maven Plugin subproject diff --git a/infra/database/type/presto/src/main/java/org/apache/shardingsphere/infra/database/presto/metadata/data/loader/PrestoMetaDataLoader.java b/infra/database/type/presto/src/main/java/org/apache/shardingsphere/infra/database/presto/metadata/data/loader/PrestoMetaDataLoader.java new file mode 100644 index 0000000000000..a6a9982568db0 --- /dev/null +++ b/infra/database/type/presto/src/main/java/org/apache/shardingsphere/infra/database/presto/metadata/data/loader/PrestoMetaDataLoader.java @@ -0,0 +1,114 @@ +/* + * 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.shardingsphere.infra.database.presto.metadata.data.loader; + +import org.apache.shardingsphere.infra.database.core.metadata.data.loader.DialectMetaDataLoader; +import org.apache.shardingsphere.infra.database.core.metadata.data.loader.MetaDataLoaderMaterial; +import org.apache.shardingsphere.infra.database.core.metadata.data.model.ColumnMetaData; +import org.apache.shardingsphere.infra.database.core.metadata.data.model.SchemaMetaData; +import org.apache.shardingsphere.infra.database.core.metadata.data.model.TableMetaData; +import org.apache.shardingsphere.infra.database.core.metadata.database.datatype.DataTypeRegistry; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Types; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * Meta data loader for Presto. + * As of prestodb/presto 0.290 of the Memory Connector, the table `INFORMATION_SCHEMA.INDEXES` does not exist, + * and `INFORMATION_SCHEMA.COLUMNS` does not have a column `IS_VISIBLE`. + * This may change in the future. + */ +public final class PrestoMetaDataLoader implements DialectMetaDataLoader { + + @Override + public Collection load(final MetaDataLoaderMaterial material) throws SQLException { + Collection tableMetaDataList = new LinkedList<>(); + try (Connection connection = material.getDataSource().getConnection()) { + Map> columnMetaDataMap = loadColumnMetaDataMap(connection, material.getActualTableNames()); + for (Map.Entry> entry : columnMetaDataMap.entrySet()) { + tableMetaDataList.add(new TableMetaData(entry.getKey(), entry.getValue(), Collections.emptyList(), Collections.emptyList())); + } + } + return Collections.singleton(new SchemaMetaData(material.getDefaultSchemaName(), tableMetaDataList)); + } + + @SuppressWarnings("SqlSourceToSinkFlow") + private Map> loadColumnMetaDataMap(final Connection connection, final Collection tables) throws SQLException { + Map> result = new HashMap<>(); + try (PreparedStatement preparedStatement = connection.prepareStatement(getTableMetaDataSQL(tables))) { + preparedStatement.setString(1, connection.getCatalog()); + try (ResultSet resultSet = preparedStatement.executeQuery()) { + while (resultSet.next()) { + String tableName = resultSet.getString("TABLE_NAME"); + ColumnMetaData columnMetaData = loadColumnMetaData(resultSet); + if (!result.containsKey(tableName)) { + result.put(tableName, new LinkedList<>()); + } + result.get(tableName).add(columnMetaData); + } + } + } + return result; + } + + private String getTableMetaDataSQL(final Collection tables) { + if (tables.isEmpty()) { + return "SELECT TABLE_CATALOG,\n" + + " TABLE_NAME,\n" + + " COLUMN_NAME,\n" + + " DATA_TYPE,\n" + + " ORDINAL_POSITION,\n" + + " IS_NULLABLE\n" + + "FROM INFORMATION_SCHEMA.COLUMNS\n" + + "WHERE TABLE_CATALOG = ?\n" + + "ORDER BY ORDINAL_POSITION"; + } + String collect = tables.stream().map(each -> String.format("'%s'", each).toUpperCase()).collect(Collectors.joining(",")); + return String.format("SELECT TABLE_CATALOG,\n" + + " TABLE_NAME,\n" + + " COLUMN_NAME,\n" + + " DATA_TYPE,\n" + + " ORDINAL_POSITION,\n" + + " IS_NULLABLE\n" + + "FROM INFORMATION_SCHEMA.COLUMNS\n" + + "WHERE TABLE_CATALOG = ?\n" + + " AND UPPER(TABLE_NAME) IN (%s)\n" + + "ORDER BY ORDINAL_POSITION", collect); + } + + private ColumnMetaData loadColumnMetaData(final ResultSet resultSet) throws SQLException { + String columnName = resultSet.getString("COLUMN_NAME"); + String dataType = resultSet.getString("DATA_TYPE"); + boolean isNullable = "YES".equals(resultSet.getString("IS_NULLABLE")); + return new ColumnMetaData(columnName, DataTypeRegistry.getDataType(getDatabaseType(), dataType).orElse(Types.OTHER), Boolean.FALSE, Boolean.FALSE, false, Boolean.TRUE, false, isNullable); + } + + @Override + public String getDatabaseType() { + return "Presto"; + } +} diff --git a/infra/database/type/presto/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.metadata.data.loader.DialectMetaDataLoader b/infra/database/type/presto/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.metadata.data.loader.DialectMetaDataLoader new file mode 100644 index 0000000000000..ce79600150194 --- /dev/null +++ b/infra/database/type/presto/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.metadata.data.loader.DialectMetaDataLoader @@ -0,0 +1,18 @@ +# +# 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. +# + +org.apache.shardingsphere.infra.database.presto.metadata.data.loader.PrestoMetaDataLoader diff --git a/infra/database/type/presto/src/test/java/org/apache/shardingsphere/infra/database/presto/database/PrestoDatabaseMetaDataTest.java b/infra/database/type/presto/src/test/java/org/apache/shardingsphere/infra/database/presto/database/PrestoDatabaseMetaDataTest.java new file mode 100644 index 0000000000000..ff4e4d34b9158 --- /dev/null +++ b/infra/database/type/presto/src/test/java/org/apache/shardingsphere/infra/database/presto/database/PrestoDatabaseMetaDataTest.java @@ -0,0 +1,44 @@ +/* + * 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.shardingsphere.infra.database.presto.database; + +import org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData; +import org.apache.shardingsphere.infra.database.core.metadata.database.enums.NullsOrderType; +import org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter; +import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader; +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +class PrestoDatabaseMetaDataTest { + + private final DialectDatabaseMetaData dialectDatabaseMetaData = DatabaseTypedSPILoader.getService(DialectDatabaseMetaData.class, TypedSPILoader.getService(DatabaseType.class, "Presto")); + + @Test + void assertGetQuoteCharacter() { + assertThat(dialectDatabaseMetaData.getQuoteCharacter(), is(QuoteCharacter.QUOTE)); + } + + @Test + void assertGetDefaultNullsOrderType() { + assertThat(dialectDatabaseMetaData.getDefaultNullsOrderType(), is(NullsOrderType.LOW)); + } +} diff --git a/infra/reachability-metadata/src/main/resources/META-INF/native-image/com.facebook.presto/presto-jdbc/0.290/proxy-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/com.facebook.presto/presto-jdbc/0.290/proxy-config.json new file mode 100644 index 0000000000000..2fcd0d1191f5d --- /dev/null +++ b/infra/reachability-metadata/src/main/resources/META-INF/native-image/com.facebook.presto/presto-jdbc/0.290/proxy-config.json @@ -0,0 +1,6 @@ +[ + { + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.guava.reflect.Reflection"}, + "interfaces":["java.lang.reflect.TypeVariable"] + } +] diff --git a/infra/reachability-metadata/src/main/resources/META-INF/native-image/com.facebook.presto/presto-jdbc/0.290/reflect-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/com.facebook.presto/presto-jdbc/0.290/reflect-config.json new file mode 100644 index 0000000000000..a9eb685bc0425 --- /dev/null +++ b/infra/reachability-metadata/src/main/resources/META-INF/native-image/com.facebook.presto/presto-jdbc/0.290/reflect-config.json @@ -0,0 +1,182 @@ +[ +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.client.StatementClientV1"}, + "name":"com.facebook.presto.jdbc.internal.client.ClientTypeSignature", + "methods":[{"name":"","parameterTypes":["java.lang.String","java.util.List","java.util.List","java.util.List"] }] +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.jackson.databind.ObjectReader"}, + "name":"com.facebook.presto.jdbc.internal.client.ClientTypeSignature", + "allDeclaredFields":true, + "queryAllDeclaredMethods":true, + "queryAllDeclaredConstructors":true +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.jackson.databind.deser.DefaultDeserializationContext"}, + "name":"com.facebook.presto.jdbc.internal.client.ClientTypeSignatureParameter$ClientTypeSignatureParameterDeserializer", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.client.StatementClientV1"}, + "name":"com.facebook.presto.jdbc.internal.client.Column", + "methods":[{"name":"","parameterTypes":["java.lang.String","java.lang.String","com.facebook.presto.jdbc.internal.client.ClientTypeSignature"] }] +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.jackson.databind.ObjectReader"}, + "name":"com.facebook.presto.jdbc.internal.client.Column", + "allDeclaredFields":true, + "queryAllDeclaredMethods":true, + "queryAllDeclaredConstructors":true +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.jackson.databind.ObjectReader"}, + "name":"com.facebook.presto.jdbc.internal.client.ErrorLocation", + "allDeclaredFields":true, + "queryAllDeclaredMethods":true, + "queryAllDeclaredConstructors":true +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.jackson.databind.ObjectReader"}, + "name":"com.facebook.presto.jdbc.internal.client.FailureInfo", + "allDeclaredFields":true, + "queryAllDeclaredMethods":true, + "queryAllDeclaredConstructors":true, + "allPublicConstructors": true +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.jackson.databind.ObjectReader"}, + "name":"com.facebook.presto.jdbc.internal.client.QueryData", + "queryAllDeclaredMethods":true +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.jackson.databind.ObjectReader"}, + "name":"com.facebook.presto.jdbc.internal.client.QueryError", + "allDeclaredFields":true, + "queryAllDeclaredMethods":true, + "queryAllDeclaredConstructors":true, + "allPublicConstructors": true +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.jackson.databind.ObjectReader"}, + "name":"com.facebook.presto.jdbc.internal.client.QueryResults", + "allDeclaredFields":true, + "queryAllDeclaredMethods":true, + "queryAllDeclaredConstructors":true, + "methods":[{"name":"","parameterTypes":["java.lang.String","java.net.URI","java.net.URI","java.net.URI","java.util.List","java.util.List","java.util.List","com.facebook.presto.jdbc.internal.client.StatementStats","com.facebook.presto.jdbc.internal.client.QueryError","java.util.List","java.lang.String","java.lang.Long"] }] +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.jackson.databind.ObjectReader"}, + "name":"com.facebook.presto.jdbc.internal.client.QueryStatusInfo", + "queryAllDeclaredMethods":true +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.PrestoPreparedStatement"}, + "name":"com.facebook.presto.jdbc.internal.client.StageStats", + "methods":[{"name":"","parameterTypes":["java.lang.String","java.lang.String","boolean","int","int","int","int","int","long","long","long","long","java.util.List"] }] +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.PrestoResultSet$ResultsPageIterator"}, + "name":"com.facebook.presto.jdbc.internal.client.StageStats", + "methods":[{"name":"","parameterTypes":["java.lang.String","java.lang.String","boolean","int","int","int","int","int","long","long","long","long","java.util.List"] }] +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.PrestoStatement"}, + "name":"com.facebook.presto.jdbc.internal.client.StageStats", + "methods":[{"name":"","parameterTypes":["java.lang.String","java.lang.String","boolean","int","int","int","int","int","long","long","long","long","java.util.List"] }] +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.jackson.databind.ObjectReader"}, + "name":"com.facebook.presto.jdbc.internal.client.StageStats", + "allDeclaredFields":true, + "queryAllDeclaredMethods":true, + "queryAllDeclaredConstructors":true +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.jackson.databind.ObjectReader"}, + "name":"com.facebook.presto.jdbc.internal.client.StatementStats", + "allDeclaredFields":true, + "queryAllDeclaredMethods":true, + "queryAllDeclaredConstructors":true, + "methods":[{"name":"","parameterTypes":["java.lang.String","boolean","boolean","boolean","int","int","int","int","int","long","long","long","long","long","long","long","long","long","long","long","com.facebook.presto.jdbc.internal.client.StageStats","com.facebook.presto.jdbc.internal.common.RuntimeStats"] }] +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.jackson.databind.deser.std.MapDeserializer"}, + "name":"com.facebook.presto.jdbc.internal.common.RuntimeMetric", + "allDeclaredFields":true, + "queryAllDeclaredMethods":true, + "queryAllDeclaredConstructors":true, + "methods":[{"name":"","parameterTypes":["java.lang.String","com.facebook.presto.jdbc.internal.common.RuntimeUnit","long","long","long","long"] }] +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.jackson.databind.ObjectReader"}, + "name":"com.facebook.presto.jdbc.internal.common.RuntimeStats", + "allDeclaredFields":true, + "queryAllDeclaredMethods":true, + "queryAllDeclaredConstructors":true +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.jackson.databind.introspect.AnnotatedConstructor"}, + "name":"com.facebook.presto.jdbc.internal.common.RuntimeStats", + "methods":[{"name":"","parameterTypes":["java.util.Map"] }] +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.jackson.databind.deser.std.MapDeserializer"}, + "name":"com.facebook.presto.jdbc.internal.common.RuntimeUnit", + "allDeclaredFields":true, + "queryAllDeclaredMethods":true +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.jackson.databind.introspect.JacksonAnnotationIntrospector"}, + "name":"com.facebook.presto.jdbc.internal.common.RuntimeUnit", + "allDeclaredFields":true +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.jackson.databind.util.ClassUtil"}, + "name":"com.facebook.presto.jdbc.internal.common.RuntimeUnit", + "allDeclaredFields":true +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.jackson.databind.ObjectMapper"}, + "name":"com.facebook.presto.jdbc.internal.common.type.ParameterKind", + "allDeclaredFields":true, + "queryAllDeclaredMethods":true +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.jackson.databind.introspect.AnnotatedMethod"}, + "name":"com.facebook.presto.jdbc.internal.common.type.ParameterKind", + "methods":[{"name":"fromJsonValue","parameterTypes":["java.lang.String"] }] +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.guava.reflect.Types$TypeVariableInvocationHandler"}, + "name":"com.facebook.presto.jdbc.internal.guava.reflect.Types$TypeVariableImpl", + "queryAllPublicMethods":true +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.jackson.databind.ext.Java7Handlers"}, + "name":"com.facebook.presto.jdbc.internal.jackson.databind.ext.Java7HandlersImpl", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.jackson.databind.ext.Java7Support"}, + "name":"com.facebook.presto.jdbc.internal.jackson.databind.ext.Java7SupportImpl", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.com.facebook.airlift.json.ObjectMapperProvider"}, + "name":"com.facebook.presto.jdbc.internal.joda.time.DateTime" +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.jackson.databind.ObjectReader"}, + "name":"com.facebook.presto.jdbc.internal.spi.PrestoWarning", + "allDeclaredFields":true, + "queryAllDeclaredMethods":true, + "queryAllDeclaredConstructors":true +}, +{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.jackson.databind.ObjectReader"}, + "name":"com.facebook.presto.jdbc.internal.spi.WarningCode", + "allDeclaredFields":true, + "queryAllDeclaredMethods":true, + "queryAllDeclaredConstructors":true +} +] diff --git a/infra/reachability-metadata/src/main/resources/META-INF/native-image/com.facebook.presto/presto-jdbc/0.290/resource-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/com.facebook.presto/presto-jdbc/0.290/resource-config.json new file mode 100644 index 0000000000000..2c27085c6f7b6 --- /dev/null +++ b/infra/reachability-metadata/src/main/resources/META-INF/native-image/com.facebook.presto/presto-jdbc/0.290/resource-config.json @@ -0,0 +1,29 @@ +{ + "resources":{ + "includes":[{ + "condition":{"typeReachable":"com.facebook.presto.jdbc.PrestoDriver"}, + "pattern":"\\QMETA-INF/services/java.net.spi.URLStreamHandlerProvider\\E" + }, { + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.common.type.TimeZoneKey"}, + "pattern":"\\Qcom/facebook/presto/jdbc/internal/common/type/zone-index.properties\\E" + }, { + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.okhttp3.internal.tls.BasicTrustRootIndex"}, + "pattern":"java.base:\\Qjdk/internal/icu/impl/data/icudt74b/nfkc.nrm\\E" + }, { + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.okhttp3.internal.Util"}, + "pattern":"java.base:\\Qjdk/internal/icu/impl/data/icudt74b/uprops.icu\\E" + }, { + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.okhttp3.internal.Util"}, + "pattern":"java.base:\\Qsun/net/idn/uidna.spp\\E" + }, { + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.joda.time.tz.ZoneInfoProvider"}, + "pattern":"\\Qcom/facebook/presto/jdbc/internal/joda/time/tz/data/ZoneInfoMap\\E" + }, { + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.joda.time.tz.ZoneInfoProvider"}, + "pattern":"\\Qcom/facebook/presto/jdbc/internal/joda/time/tz/data/Asia/Shanghai\\E" + }, { + "condition":{"typeReachable":"com.facebook.presto.jdbc.internal.joda.time.tz.ZoneInfoProvider"}, + "pattern":"\\Qcom/facebook/presto/jdbc/internal/joda/time/tz/data/Etc/UTC\\E" + }]}, + "bundles":[] +} diff --git a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/reflect-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/reflect-config.json index e7fb0c4c8f095..dcb6ba2fd3202 100644 --- a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/reflect-config.json +++ b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/reflect-config.json @@ -3,10 +3,6 @@ "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource"}, "name":"JdkLogger" }, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine"}, - "name":"JdkLogger" -}, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.standalone.jdbc.sql.JDBCRepositorySQLLoader"}, "name":"[Lcom.fasterxml.jackson.databind.deser.BeanDeserializerModifier;" @@ -24,7 +20,7 @@ "name":"[Lcom.github.dockerjava.api.model.VolumesFrom;" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager$$Lambda/0x00007fce2fcdb068"}, + "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager$$Lambda/0x00007f5c13ce4890"}, "name":"[Lcom.zaxxer.hikari.util.ConcurrentBag$IConcurrentBagEntry;" }, { @@ -55,6 +51,10 @@ "condition":{"typeReachable":"org.apache.shardingsphere.infra.database.postgresql.metadata.data.loader.PostgreSQLMetaDataLoader"}, "name":"[Lcom.zaxxer.hikari.util.ConcurrentBag$IConcurrentBagEntry;" }, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.infra.database.presto.metadata.data.loader.PrestoMetaDataLoader"}, + "name":"[Lcom.zaxxer.hikari.util.ConcurrentBag$IConcurrentBagEntry;" +}, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.database.sqlserver.metadata.data.loader.SQLServerMetaDataLoader"}, "name":"[Lcom.zaxxer.hikari.util.ConcurrentBag$IConcurrentBagEntry;" @@ -382,7 +382,7 @@ "allDeclaredFields":true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.persist.service.unified.ComputeNodePersistService"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.state.node.ComputeNodePersistService"}, "name":"java.lang.Object", "allDeclaredFields":true }, @@ -749,6 +749,11 @@ "queryAllPublicConstructors":true, "methods":[{"name":"","parameterTypes":[] }, {"name":"add","parameterTypes":["long"] }, {"name":"sum","parameterTypes":[] }] }, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask"}, + "name":"java.util.concurrent.atomic.Striped64$Cell", + "fields":[{"name":"value"}] +}, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.expr.groovy.GroovyInlineExpressionParser"}, "name":"java.util.function.DoubleFunction", @@ -1594,6 +1599,22 @@ "condition":{"typeReachable":"org.apache.shardingsphere.infra.props.TypedPropertyValue"}, "name":"org.apache.shardingsphere.infra.database.postgresql.type.PostgreSQLDatabaseType" }, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor"}, + "name":"org.apache.shardingsphere.infra.database.presto.connector.PrestoConnectionPropertiesParser" +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.infra.database.core.metadata.data.loader.MetaDataLoader"}, + "name":"org.apache.shardingsphere.infra.database.presto.metadata.data.loader.PrestoMetaDataLoader" +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry"}, + "name":"org.apache.shardingsphere.infra.database.presto.metadata.database.PrestoDatabaseMetaData" +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.infra.props.TypedPropertyValue"}, + "name":"org.apache.shardingsphere.infra.database.presto.type.PrestoDatabaseType" +}, { "condition":{"typeReachable":"org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor"}, "name":"org.apache.shardingsphere.infra.database.sql92.connector.SQL92ConnectionPropertiesParser" @@ -1703,18 +1724,18 @@ "methods":[{"name":"","parameterTypes":[] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.persist.service.unified.ComputeNodePersistService"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.state.node.ComputeNodePersistService"}, "name":"org.apache.shardingsphere.infra.instance.yaml.YamlComputeNodeData", "allDeclaredFields":true, "queryAllPublicMethods":true, "methods":[{"name":"","parameterTypes":[] }, {"name":"getAttribute","parameterTypes":[] }, {"name":"getDatabaseName","parameterTypes":[] }, {"name":"getVersion","parameterTypes":[] }, {"name":"setAttribute","parameterTypes":["java.lang.String"] }, {"name":"setDatabaseName","parameterTypes":["java.lang.String"] }, {"name":"setVersion","parameterTypes":["java.lang.String"] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.persist.service.unified.ComputeNodePersistService"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.state.node.ComputeNodePersistService"}, "name":"org.apache.shardingsphere.infra.instance.yaml.YamlComputeNodeDataBeanInfo" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.persist.service.unified.ComputeNodePersistService"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.state.node.ComputeNodePersistService"}, "name":"org.apache.shardingsphere.infra.instance.yaml.YamlComputeNodeDataCustomizer" }, { @@ -1744,7 +1765,7 @@ "queryAllPublicMethods":true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.persist.service.unified.ComputeNodePersistService"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.state.node.ComputeNodePersistService"}, "name":"org.apache.shardingsphere.infra.util.yaml.YamlConfiguration", "queryAllPublicMethods":true }, @@ -3386,6 +3407,30 @@ "name":"org.apache.shardingsphere.sql.parser.postgresql.visitor.statement.type.PostgreSQLDMLStatementVisitor", "methods":[{"name":"","parameterTypes":[] }] }, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement"}, + "name":"org.apache.shardingsphere.sql.parser.presto.parser.PrestoLexer", + "methods":[{"name":"","parameterTypes":["org.antlr.v4.runtime.CharStream"] }] +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement"}, + "name":"org.apache.shardingsphere.sql.parser.presto.parser.PrestoParser", + "methods":[{"name":"","parameterTypes":["org.antlr.v4.runtime.TokenStream"] }] +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.proxy.backend.handler.ProxySQLComQueryParser"}, + "name":"org.apache.shardingsphere.sql.parser.presto.parser.PrestoParserFacade" +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.core.database.visitor.SQLStatementVisitorFactory"}, + "name":"org.apache.shardingsphere.sql.parser.presto.visitor.statement.PrestoStatementVisitorFacade", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement"}, + "name":"org.apache.shardingsphere.sql.parser.presto.visitor.statement.type.PrestoDDLStatementVisitor", + "methods":[{"name":"","parameterTypes":[] }] +}, { "condition":{"typeReachable":"org.apache.shardingsphere.proxy.backend.handler.ProxySQLComQueryParser"}, "name":"org.apache.shardingsphere.sql.parser.sql92.parser.SQL92ParserFacade" @@ -3589,6 +3634,16 @@ "name":"org.apache.shardingsphere.sql.parser.statement.postgresql.dml.PostgreSQLSelectStatement", "methods":[{"name":"","parameterTypes":[] }] }, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement"}, + "name":"org.apache.shardingsphere.sql.parser.statement.presto.dml.PrestoInsertStatement", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement"}, + "name":"org.apache.shardingsphere.sql.parser.statement.presto.dml.PrestoSelectStatement", + "methods":[{"name":"","parameterTypes":[] }] +}, { "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement"}, "name":"org.apache.shardingsphere.sql.parser.statement.sqlserver.ddl.SQLServerCreateTableStatement", @@ -3789,10 +3844,5 @@ { "condition":{"typeReachable":"org.apache.shardingsphere.proxy.initializer.BootstrapInitializer"}, "name":"org.apache.shardingsphere.transaction.yaml.config.YamlTransactionRuleConfigurationCustomizer" -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine"}, - "name":"sun.security.provider.SecureRandom", - "methods":[{"name":"","parameterTypes":[] }, {"name":"","parameterTypes":["java.security.SecureRandomParameters"] }] } ] \ No newline at end of file diff --git a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/resource-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/resource-config.json index 4c9b2053c99e9..ad71782c962ef 100644 --- a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/resource-config.json +++ b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/resource-config.json @@ -79,7 +79,7 @@ "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager"}, "pattern":"\\QMETA-INF/services/com.clickhouse.client.ClickHouseClient\\E" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager$$Lambda/0x00007fce2fb3fc30"}, + "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager$$Lambda/0x00007f5c13b6a710"}, "pattern":"\\QMETA-INF/services/com.clickhouse.client.ClickHouseClient\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource"}, @@ -317,7 +317,7 @@ "pattern":"\\QMETA-INF/services/org.apache.shardingsphere.mode.persist.coordinator.PersistCoordinatorFacadeBuilder\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.proxy.initializer.BootstrapInitializer"}, - "pattern":"\\QMETA-INF/services/org.apache.shardingsphere.mode.persist.service.divided.PersistServiceBuilder\\E" + "pattern":"\\QMETA-INF/services/org.apache.shardingsphere.mode.persist.service.PersistServiceBuilder\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.cluster.lock.holder.DistributedLockHolder"}, "pattern":"\\QMETA-INF/services/org.apache.shardingsphere.mode.repository.cluster.lock.creator.DistributedLockCreator\\E" @@ -2037,6 +2037,9 @@ }, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.url.classpath.ClassPathURLLoader"}, "pattern":"\\Qtest-native/yaml/jdbc/databases/postgresql.yaml\\E" + }, { + "condition":{"typeReachable":"org.apache.shardingsphere.infra.url.classpath.ClassPathURLLoader"}, + "pattern":"\\Qtest-native/yaml/jdbc/databases/presto.yaml\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.url.classpath.ClassPathURLLoader"}, "pattern":"\\Qtest-native/yaml/jdbc/databases/sqlserver.yaml\\E" diff --git a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/reflect-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/reflect-config.json index 7cdc40c4f3c6f..cbc991c7c295e 100644 --- a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/reflect-config.json +++ b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/reflect-config.json @@ -367,6 +367,16 @@ "name":"org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdDropTableStatement", "methods":[{"name":"","parameterTypes":[] }] }, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.presto.visitor.statement.type.PrestoDMLStatementVisitor"}, + "name":"org.apache.shardingsphere.sql.parser.presto.visitor.statement.type.PrestoDMLStatementVisitor", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.statement.presto.ddl.PrestoDropTableStatement"}, + "name":"org.apache.shardingsphere.sql.parser.statement.presto.ddl.PrestoDropTableStatement", + "methods":[{"name":"","parameterTypes":[] }] +}, { "condition":{"typeReachable":"javax.security.auth.login.Configuration"}, "name":"sun.security.provider.ConfigFile", diff --git a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.hamcrest/hamcrest/3.0/reflect-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.hamcrest/hamcrest/3.0/reflect-config.json new file mode 100644 index 0000000000000..8e2d43f525d5f --- /dev/null +++ b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.hamcrest/hamcrest/3.0/reflect-config.json @@ -0,0 +1,18 @@ +[ +{ + "condition":{"typeReachable":"org.hamcrest.internal.ReflectiveTypeFinder"}, + "name":"org.hamcrest.comparator.ComparatorMatcherBuilder$ComparatorMatcher", + "queryAllDeclaredMethods":true, + "allDeclaredMethods": true +}, +{ + "condition":{"typeReachable":"org.hamcrest.internal.ReflectiveTypeFinder"}, + "name":"org.hamcrest.TypeSafeMatcher", + "allDeclaredMethods": true +}, +{ + "condition":{"typeReachable":"org.hamcrest.internal.ReflectiveTypeFinder"}, + "name":"org.hamcrest.BaseMatcher", + "allDeclaredMethods": true +} +] diff --git a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.junit.jupiter/junit-jupiter/5.11.1/reflect-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.junit.jupiter/junit-jupiter/5.11.1/reflect-config.json index 4acfe31d5f984..b40a85928619f 100644 --- a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.junit.jupiter/junit-jupiter/5.11.1/reflect-config.json +++ b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.junit.jupiter/junit-jupiter/5.11.1/reflect-config.json @@ -33,5 +33,10 @@ "condition":{"typeReachable":"org.junit.platform.commons.util.ReflectionUtils"}, "name":"org.junit.internal.AssumptionViolatedException", "allPublicMethods": true +}, +{ + "condition":{"typeReachable":"org.junit.platform.commons.util.AnnotationUtils"}, + "name":"org.junit.jupiter.api.Disabled", + "allPublicMethods": true } ] diff --git a/pom.xml b/pom.xml index 47dfbde8720d5..f64be13ddb671 100644 --- a/pom.xml +++ b/pom.xml @@ -131,7 +131,7 @@ 4.0.1 1.6.0 3.3.6 - 0.288.1 + 0.290 5.0.6.java8 4.0.3 diff --git a/test/native/pom.xml b/test/native/pom.xml index 653c4d152aa18..7cc84033b5059 100644 --- a/test/native/pom.xml +++ b/test/native/pom.xml @@ -142,6 +142,12 @@ ${project.version} test + + org.apache.shardingsphere + shardingsphere-parser-sql-presto + ${project.version} + test + org.awaitility @@ -207,6 +213,11 @@ jaybird test + + com.facebook.presto + presto-jdbc + test + org.testcontainers junit-jupiter diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/commons/TestShardingService.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/commons/TestShardingService.java index 552484ede967d..004ccc83476b3 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/commons/TestShardingService.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/commons/TestShardingService.java @@ -125,6 +125,19 @@ public void processSuccessInHive() throws SQLException { assertThat(addressRepository.selectAll(), equalTo(Collections.emptyList())); } + /** + * Process success in Presto Memory Connector. + * TODO ShardingSphere's Presto integration has a bug in transaction support. + * Can't execute {@code orderItemRepository.assertRollbackWithTransactions();} here. + * Presto Memory Connector does not support `DELETE FROM` SQL. + * + * @throws SQLException SQL exception + */ + public void processSuccessInPresto() throws SQLException { + insertData(Statement.RETURN_GENERATED_KEYS); + extracted(); + } + /** * Insert data. * diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/PrestoTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/PrestoTest.java new file mode 100644 index 0000000000000..46a5c60e268f9 --- /dev/null +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/PrestoTest.java @@ -0,0 +1,169 @@ +/* + * 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.shardingsphere.test.natived.jdbc.databases; + +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; +import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; +import org.apache.shardingsphere.mode.manager.ContextManager; +import org.apache.shardingsphere.test.natived.commons.TestShardingService; +import org.awaitility.Awaitility; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledInNativeImage; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.containers.wait.strategy.WaitAllStrategy; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; +import org.testcontainers.utility.MountableFile; + +import javax.sql.DataSource; +import java.nio.file.Paths; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; +import java.time.Duration; +import java.util.stream.Stream; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +/** + * Unable to use `org.testcontainers:presto:1.20.4` under GraalVM Native Image. + * Background comes from testcontainers/testcontainers-java#8657. + */ +@SuppressWarnings({"resource", "SqlNoDataSourceInspection"}) +@EnabledInNativeImage +@Testcontainers +public class PrestoTest { + + private final String systemPropKeyPrefix = "fixture.test-native.yaml.database.presto."; + + private String baseJdbcUrl; + + @Container + private final GenericContainer container = new GenericContainer<>("prestodb/presto:0.290") + .withExposedPorts(8080) + .withCopyFileToContainer( + MountableFile.forHostPath(Paths.get("src/test/resources/test-native/properties/presto-memory.properties").toAbsolutePath()), + "/opt/presto-server/etc/catalog/memory.properties") + .withCopyFileToContainer( + MountableFile.forHostPath(Paths.get("src/test/resources/test-native/properties/presto-config.properties").toAbsolutePath()), + "/opt/presto-server/etc/config.properties") + .waitingFor( + new WaitAllStrategy() + .withStrategy(Wait.forLogMessage(".*======== SERVER STARTED ========.*", 1)) + .withStrategy(Wait.forHttp("/v1/info/state").forPort(8080).forResponsePredicate("\"ACTIVE\""::equals))); + + private DataSource logicDataSource; + + @BeforeEach + void beforeEach() { + assertThat(System.getProperty(systemPropKeyPrefix + "ds0.jdbc-url"), is(nullValue())); + assertThat(System.getProperty(systemPropKeyPrefix + "ds1.jdbc-url"), is(nullValue())); + assertThat(System.getProperty(systemPropKeyPrefix + "ds2.jdbc-url"), is(nullValue())); + } + + @AfterEach + void afterEach() throws SQLException { + try (Connection connection = logicDataSource.getConnection()) { + ContextManager contextManager = connection.unwrap(ShardingSphereConnection.class).getContextManager(); + for (StorageUnit each : contextManager.getStorageUnits(DefaultDatabase.LOGIC_NAME).values()) { + each.getDataSource().unwrap(HikariDataSource.class).close(); + } + contextManager.close(); + } + System.clearProperty(systemPropKeyPrefix + "ds0.jdbc-url"); + System.clearProperty(systemPropKeyPrefix + "ds1.jdbc-url"); + System.clearProperty(systemPropKeyPrefix + "ds2.jdbc-url"); + } + + @Test + void assertShardingInLocalTransactions() throws SQLException { + baseJdbcUrl = "jdbc:presto://localhost:" + container.getMappedPort(8080) + "/memory"; + logicDataSource = createDataSource(); + TestShardingService testShardingService = new TestShardingService(logicDataSource); + testShardingService.processSuccessInPresto(); + testShardingService.cleanEnvironment(); + } + + private DataSource createDataSource() throws SQLException { + Awaitility.await().atMost(Duration.ofMinutes(1L)).ignoreExceptions().until(() -> { + DriverManager.getConnection(baseJdbcUrl, "test", null).close(); + return true; + }); + try ( + Connection connection = DriverManager.getConnection(baseJdbcUrl, "test", null); + Statement statement = connection.createStatement()) { + statement.execute("CREATE SCHEMA memory.demo_ds_0"); + statement.execute("CREATE SCHEMA memory.demo_ds_1"); + statement.execute("CREATE SCHEMA memory.demo_ds_2"); + } + Stream.of("demo_ds_0", "demo_ds_1", "demo_ds_2").forEach(this::initSchema); + HikariConfig config = new HikariConfig(); + config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver"); + config.setJdbcUrl("jdbc:shardingsphere:classpath:test-native/yaml/jdbc/databases/presto.yaml?placeholder-type=system_props"); + System.setProperty(systemPropKeyPrefix + "ds0.jdbc-url", baseJdbcUrl + "/demo_ds_0"); + System.setProperty(systemPropKeyPrefix + "ds1.jdbc-url", baseJdbcUrl + "/demo_ds_1"); + System.setProperty(systemPropKeyPrefix + "ds2.jdbc-url", baseJdbcUrl + "/demo_ds_2"); + return new HikariDataSource(config); + } + + /** + * TODO `shardingsphere-parser-sql-presto` module does not support `create table` statements yet. + * Presto Memory Connector does not support AUTO_INCREMENT columns. + * Presto Memory Connector does not support non-null column for column name. + * Presto Memory Connector does not support Primary Key constraints. + * Presto Memory Connector does not support `truncate table` SQL. + * + * @param schemaName schema name + * @throws RuntimeException Runtime exception + */ + private void initSchema(final String schemaName) { + try ( + Connection connection = DriverManager.getConnection(baseJdbcUrl + "/" + schemaName, "test", null); + Statement statement = connection.createStatement()) { + statement.execute("CREATE TABLE t_order (\n" + + " order_id BIGINT,\n" + + " order_type INTEGER,\n" + + " user_id INTEGER,\n" + + " address_id BIGINT,\n" + + " status VARCHAR(50)\n" + + ")"); + statement.execute("CREATE TABLE IF NOT EXISTS t_order_item (\n" + + " order_item_id BIGINT,\n" + + " order_id BIGINT,\n" + + " user_id INT,\n" + + " phone VARCHAR(50),\n" + + " status VARCHAR(50)\n" + + ")"); + statement.execute("CREATE TABLE IF NOT EXISTS t_address (\n" + + " address_id BIGINT,\n" + + " address_name VARCHAR(100)\n" + + ")"); + } catch (final SQLException ex) { + throw new RuntimeException(ex); + } + } +} diff --git a/test/native/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/reflect-config.json b/test/native/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/reflect-config.json index 996859280ee63..345ae2c2a8b98 100644 --- a/test/native/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/reflect-config.json +++ b/test/native/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/reflect-config.json @@ -9,14 +9,6 @@ "name":"org.apache.shardingsphere.test.natived.commons.algorithm.TestQueryAssistedShardingEncryptAlgorithm", "methods":[{"name":"","parameterTypes":[] }] }, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.test.natived.proxy.databases.MySQLTest"}, - "name":"org.apache.shardingsphere.test.natived.proxy.databases.MySQLTest", - "allDeclaredConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredFields": true -}, { "condition":{"typeReachable":"org.apache.shardingsphere.test.natived.jdbc.transactions.xa.NarayanaTest"}, "name":"org.apache.shardingsphere.test.natived.jdbc.transactions.xa.NarayanaTest", @@ -33,14 +25,6 @@ "allPublicMethods": true, "allDeclaredFields": true }, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.test.natived.proxy.databases.PostgresTest"}, - "name":"org.apache.shardingsphere.test.natived.proxy.databases.PostgresTest", - "allDeclaredConstructors": true, - "allDeclaredMethods": true, - "allPublicMethods": true, - "allDeclaredFields": true -}, { "condition":{"typeReachable":"org.apache.shardingsphere.test.natived.jdbc.modes.cluster.ZookeeperTest"}, "name":"org.apache.shardingsphere.test.natived.jdbc.modes.cluster.ZookeeperTest", @@ -178,16 +162,40 @@ "allPublicMethods": true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.test.natived.proxy.transactions.base.SeataTest"}, - "name":"org.apache.shardingsphere.test.natived.proxy.transactions.base.SeataTest", + "condition":{"typeReachable":"org.apache.shardingsphere.test.natived.jdbc.databases.FirebirdTest"}, + "name":"org.apache.shardingsphere.test.natived.jdbc.databases.FirebirdTest", "allDeclaredFields": true, "allDeclaredConstructors": true, "allDeclaredMethods": true, "allPublicMethods": true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.test.natived.jdbc.databases.FirebirdTest"}, - "name":"org.apache.shardingsphere.test.natived.jdbc.databases.FirebirdTest", + "condition":{"typeReachable":"org.apache.shardingsphere.test.natived.jdbc.databases.PrestoTest"}, + "name":"org.apache.shardingsphere.test.natived.jdbc.databases.PrestoTest", + "allDeclaredFields": true, + "allDeclaredConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.test.natived.proxy.databases.MySQLTest"}, + "name":"org.apache.shardingsphere.test.natived.proxy.databases.MySQLTest", + "allDeclaredConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredFields": true +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.test.natived.proxy.databases.PostgresTest"}, + "name":"org.apache.shardingsphere.test.natived.proxy.databases.PostgresTest", + "allDeclaredConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredFields": true +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.test.natived.proxy.transactions.base.SeataTest"}, + "name":"org.apache.shardingsphere.test.natived.proxy.transactions.base.SeataTest", "allDeclaredFields": true, "allDeclaredConstructors": true, "allDeclaredMethods": true, diff --git a/test/native/src/test/resources/test-native/properties/presto-config.properties b/test/native/src/test/resources/test-native/properties/presto-config.properties new file mode 100644 index 0000000000000..dd9f08e3499af --- /dev/null +++ b/test/native/src/test/resources/test-native/properties/presto-config.properties @@ -0,0 +1,25 @@ +# +# 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. +# + +coordinator=true +node-scheduler.include-coordinator=true +http-server.http.port=8080 +discovery-server.enabled=true +discovery.uri=http://localhost:8080 +cluster.required-workers-active=1 +cluster.required-resource-managers-active=1 +cluster.required-coordinators-active=1 diff --git a/test/native/src/test/resources/test-native/properties/presto-memory.properties b/test/native/src/test/resources/test-native/properties/presto-memory.properties new file mode 100644 index 0000000000000..2d8a5793ac708 --- /dev/null +++ b/test/native/src/test/resources/test-native/properties/presto-memory.properties @@ -0,0 +1,18 @@ +# +# 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. +# + +connector.name=memory diff --git a/test/native/src/test/resources/test-native/yaml/jdbc/databases/presto.yaml b/test/native/src/test/resources/test-native/yaml/jdbc/databases/presto.yaml new file mode 100644 index 0000000000000..7e9ef8b8e7a6f --- /dev/null +++ b/test/native/src/test/resources/test-native/yaml/jdbc/databases/presto.yaml @@ -0,0 +1,66 @@ +# +# 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. +# + +dataSources: + ds_0: + dataSourceClassName: com.zaxxer.hikari.HikariDataSource + driverClassName: com.facebook.presto.jdbc.PrestoDriver + jdbcUrl: $${fixture.test-native.yaml.database.presto.ds0.jdbc-url::} + username: test + ds_1: + dataSourceClassName: com.zaxxer.hikari.HikariDataSource + driverClassName: com.facebook.presto.jdbc.PrestoDriver + jdbcUrl: $${fixture.test-native.yaml.database.presto.ds1.jdbc-url::} + username: test + ds_2: + dataSourceClassName: com.zaxxer.hikari.HikariDataSource + driverClassName: com.facebook.presto.jdbc.PrestoDriver + jdbcUrl: $${fixture.test-native.yaml.database.presto.ds2.jdbc-url::} + username: test + +rules: +- !SHARDING + tables: + t_order: + actualDataNodes: ds_0.t_order, ds_1.t_order, ds_2.t_order + keyGenerateStrategy: + column: order_id + keyGeneratorName: snowflake + t_order_item: + actualDataNodes: ds_0.t_order_item, ds_1.t_order_item, ds_2.t_order_item + keyGenerateStrategy: + column: order_item_id + keyGeneratorName: snowflake + defaultDatabaseStrategy: + standard: + shardingColumn: user_id + shardingAlgorithmName: inline + shardingAlgorithms: + inline: + type: CLASS_BASED + props: + strategy: STANDARD + algorithmClassName: org.apache.shardingsphere.test.natived.commons.algorithm.ClassBasedInlineShardingAlgorithmFixture + keyGenerators: + snowflake: + type: SNOWFLAKE + auditors: + sharding_key_required_auditor: + type: DML_SHARDING_CONDITIONS +- !BROADCAST + tables: + - t_address