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 30ff0a61833839..5611f45a39f146 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 @@ -24,6 +24,17 @@ ShardingSphere JDBC 要求在如下或更高版本的 `GraalVM CE` 完成构建 但这将导致集成部分第三方依赖时,构建 GraalVM Native Image 失败。 典型的例子来自 HiveServer2 JDBC Driver 相关的 `org.apache.hive:hive-jdbc:4.0.0`,HiveServer2 JDBC Driver 使用了 AWT 相关的类, 而 GraalVM CE 对 `java.beans.**` package 的支持仅位于 GraalVM CE For JDK22 及更高版本。 +```shell +com.sun.beans.introspect.ClassInfo was unintentionally initialized at build time. To see why com.sun.beans.introspect.ClassInfo got initialized use --trace-class-initialization=com.sun.beans.introspect.ClassInfo +java.beans.Introspector was unintentionally initialized at build time. To see why java.beans.Introspector got initialized use --trace-class-initialization=java.beans.Introspector +com.sun.beans.util.Cache$Kind$2 was unintentionally initialized at build time. To see why com.sun.beans.util.Cache$Kind$2 got initialized use --trace-class-initialization=com.sun.beans.util.Cache$Kind$2 +com.sun.beans.TypeResolver was unintentionally initialized at build time. To see why com.sun.beans.TypeResolver got initialized use --trace-class-initialization=com.sun.beans.TypeResolver +java.beans.ThreadGroupContext was unintentionally initialized at build time. To see why java.beans.ThreadGroupContext got initialized use --trace-class-initialization=java.beans.ThreadGroupContext +com.sun.beans.util.Cache$Kind was unintentionally initialized at build time. To see why com.sun.beans.util.Cache$Kind got initialized use --trace-class-initialization=com.sun.beans.util.Cache$Kind +com.sun.beans.introspect.MethodInfo was unintentionally initialized at build time. To see why com.sun.beans.introspect.MethodInfo got initialized use --trace-class-initialization=com.sun.beans.introspect.MethodInfo +com.sun.beans.util.Cache$Kind$1 was unintentionally initialized at build time. To see why com.sun.beans.util.Cache$Kind$1 got initialized use --trace-class-initialization=com.sun.beans.util.Cache$Kind$1 +com.sun.beans.util.Cache$Kind$3 was unintentionally initialized at build time. To see why com.sun.beans.util.Cache$Kind$3 got initialized use --trace-class-initialization=com.sun.beans.util.Cache$Kind$3 +``` ```shell com.sun.beans.introspect.ClassInfo was unintentionally initialized at build time. To see why com.sun.beans.introspect.ClassInfo got initialized use --trace-class-initialization=com.sun.beans.introspect.ClassInfo @@ -337,6 +348,110 @@ Caused by: java.io.UnsupportedEncodingException: Codepage Cp1252 is not supporte ClickHouse 不支持 ShardingSphere 集成级别的本地事务,XA 事务和 Seata AT 模式事务,更多讨论位于 https://github.com/ClickHouse/clickhouse-docs/issues/2300 。 +7. 当需要通过 ShardingSphere JDBC 使用 Hive 方言时,受未关闭的 https://github.com/apache/logging-log4j2/issues/1539 影响, +用户应排除 HiveServer2 JDBC Driver 中的 apache/logging-log4j2 和 apache/logging-log4j1 相关的库, +并使用 qos-ch/slf4j 的其他实现来完成可能需要的日志记录。受 https://issues.apache.org/jira/browse/HIVE-28308 影响, +用户不应该使用 `classifier` 为 `standalone` 的 `org.apache.hive:hive-jdbc:4.0.0`,以避免依赖冲突。 +若用户使用 qos-ch/logback 作为 qos-ch/slf4j 实现,则可能的配置例子如下, +```xml + + + + org.apache.shardingsphere + shardingsphere-jdbc + ${shardingsphere.version} + + + org.apache.shardingsphere + shardingsphere-infra-database-hive + ${project.version} + + + org.apache.shardingsphere + shardingsphere-parser-sql-hive + ${shardingsphere.version} + + + org.apache.hive + hive-jdbc + 4.0.0 + + + org.apache.hive + hive-service + 4.0.0 + + + org.apache.logging.log4j + log4j-slf4j-impl + + + org.slf4j + slf4j-reload4j + + + org.apache.logging.log4j + log4j-api + + + org.antlr + antlr4-runtime + + + org.codehaus.janino + commons-compiler + + + org.apache.commons + commons-dbcp2 + + + commons-io + commons-io + + + commons-lang + commons-lang + + + org.apache.commons + commons-pool2 + + + org.codehaus.janino + janino + + + com.fasterxml.woodstox + woodstox-core + + + org.bouncycastle + bcprov-jdk15on + + + + + org.apache.hadoop + hadoop-client-api + 3.3.5 + + + +``` +受 https://github.com/grpc/grpc-java/issues/10601 影响,用户如果在项目中引入了 `org.apache.hive:hive-service`, +则需要在项目的 classpath 的 `META-INF/native-image/io.grpc/grpc-netty-shaded` 文件夹下创建包含如下内容的文件 `native-image.properties`, +```properties +Args=--initialize-at-run-time=\ + io.grpc.netty.shaded.io.netty.channel.ChannelHandlerMask,\ + io.grpc.netty.shaded.io.netty.channel.nio.AbstractNioChannel,\ + io.grpc.netty.shaded.io.netty.channel.socket.nio.SelectorProviderUtil,\ + io.grpc.netty.shaded.io.netty.util.concurrent.DefaultPromise,\ + io.grpc.netty.shaded.io.netty.util.internal.MacAddressUtil,\ + io.grpc.netty.shaded.io.netty.util.internal.SystemPropertyUtil,\ + io.grpc.netty.shaded.io.netty.util.NetUtilInitializations +``` + ## 贡献 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 859e95e325a6b9..52b06727f94a15 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 @@ -25,6 +25,17 @@ Users can still use the old versions of GraalVM CE such as `21.0.2-graalce` on S However, this will cause the failure of building the GraalVM Native Image when integrating some third-party dependencies. A typical example is related to the `org.apache.hive:hive-jdbc:4.0.0` HiveServer2 JDBC Driver, which uses AWT-related classes. GraalVM CE only supports AWT for GraalVM CE For JDK22 and higher versions. +```shell +com.sun.beans.introspect.ClassInfo was unintentionally initialized at build time. To see why com.sun.beans.introspect.ClassInfo got initialized use --trace-class-initialization=com.sun.beans.introspect.ClassInfo +java.beans.Introspector was unintentionally initialized at build time. To see why java.beans.Introspector got initialized use --trace-class-initialization=java.beans.Introspector +com.sun.beans.util.Cache$Kind$2 was unintentionally initialized at build time. To see why com.sun.beans.util.Cache$Kind$2 got initialized use --trace-class-initialization=com.sun.beans.util.Cache$Kind$2 +com.sun.beans.TypeResolver was unintentionally initialized at build time. To see why com.sun.beans.TypeResolver got initialized use --trace-class-initialization=com.sun.beans.TypeResolver +java.beans.ThreadGroupContext was unintentionally initialized at build time. To see why java.beans.ThreadGroupContext got initialized use --trace-class-initialization=java.beans.ThreadGroupContext +com.sun.beans.util.Cache$Kind was unintentionally initialized at build time. To see why com.sun.beans.util.Cache$Kind got initialized use --trace-class-initialization=com.sun.beans.util.Cache$Kind +com.sun.beans.introspect.MethodInfo was unintentionally initialized at build time. To see why com.sun.beans.introspect.MethodInfo got initialized use --trace-class-initialization=com.sun.beans.introspect.MethodInfo +com.sun.beans.util.Cache$Kind$1 was unintentionally initialized at build time. To see why com.sun.beans.util.Cache$Kind$1 got initialized use --trace-class-initialization=com.sun.beans.util.Cache$Kind$1 +com.sun.beans.util.Cache$Kind$3 was unintentionally initialized at build time. To see why com.sun.beans.util.Cache$Kind$3 got initialized use --trace-class-initialization=com.sun.beans.util.Cache$Kind$3 +``` ```shell com.sun.beans.introspect.ClassInfo was unintentionally initialized at build time. To see why com.sun.beans.introspect.ClassInfo got initialized use --trace-class-initialization=com.sun.beans.introspect.ClassInfo @@ -352,6 +363,112 @@ Possible configuration examples are as follows, ClickHouse does not support local transactions, XA transactions, and Seata AT mode transactions at the ShardingSphere integration level. More discussion is at https://github.com/ClickHouse/clickhouse-docs/issues/2300 . +7. When using the Hive dialect via ShardingSphere JDBC, users are affected by the unresolved issue at https://github.com/apache/logging-log4j2/issues/1539, + necessitating the exclusion of libraries related to `apache/logging-log4j2` and `apache/logging-log4j1` from the HiveServer2 JDBC Driver. + Instead, they should employ alternative implementations from `qos-ch/slf4j` for any required logging functionalities. + Further, due to the impact of https://issues.apache.org/jira/browse/HIVE-28308, + users must refrain from using the `classifier` `standalone` version of `org.apache.hive:hive-jdbc:4.0.0` to circumvent dependency conflicts. + If opting for `qos-ch/logback` as the `qos-ch/slf4j` implementation, a possible configuration example could be structured as follows, +```xml + + + + org.apache.shardingsphere + shardingsphere-jdbc + ${shardingsphere.version} + + + org.apache.shardingsphere + shardingsphere-infra-database-hive + ${project.version} + + + org.apache.shardingsphere + shardingsphere-parser-sql-hive + ${shardingsphere.version} + + + org.apache.hive + hive-jdbc + 4.0.0 + + + org.apache.hive + hive-service + 4.0.0 + + + org.apache.logging.log4j + log4j-slf4j-impl + + + org.slf4j + slf4j-reload4j + + + org.apache.logging.log4j + log4j-api + + + org.antlr + antlr4-runtime + + + org.codehaus.janino + commons-compiler + + + org.apache.commons + commons-dbcp2 + + + commons-io + commons-io + + + commons-lang + commons-lang + + + org.apache.commons + commons-pool2 + + + org.codehaus.janino + janino + + + com.fasterxml.woodstox + woodstox-core + + + org.bouncycastle + bcprov-jdk15on + + + + + org.apache.hadoop + hadoop-client-api + 3.3.5 + + + +``` +Affected by https://github.com/grpc-java/issues/10601, should users incorporate `org.apache.hive:hive-service` into their project, +it is imperative to create a file named `native-image.properties` within the directory `META-INF/native-image/io.grpc/grpc-netty-shaded` of the classpath, +containing the following content, +```properties +Args=--initialize-at-run-time=\ + io.grpc.netty.shaded.io.netty.channel.ChannelHandlerMask,\ + io.grpc.netty.shaded.io.netty.channel.nio.AbstractNioChannel,\ + io.grpc.netty.shaded.io.netty.channel.socket.nio.SelectorProviderUtil,\ + io.grpc.netty.shaded.io.netty.util.concurrent.DefaultPromise,\ + io.grpc.netty.shaded.io.netty.util.internal.MacAddressUtil,\ + io.grpc.netty.shaded.io.netty.util.internal.SystemPropertyUtil,\ + io.grpc.netty.shaded.io.netty.util.NetUtilInitializations +``` + ## 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/hive/src/main/java/org/apache/shardingsphere/infra/database/hive/metadata/data/loader/HiveMetaDataLoader.java b/infra/database/type/hive/src/main/java/org/apache/shardingsphere/infra/database/hive/metadata/data/loader/HiveMetaDataLoader.java deleted file mode 100644 index 6c58c7aeb9aa6f..00000000000000 --- a/infra/database/type/hive/src/main/java/org/apache/shardingsphere/infra/database/hive/metadata/data/loader/HiveMetaDataLoader.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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.hive.metadata.data.loader; - -import org.apache.hadoop.hive.conf.HiveConf; -import org.apache.hadoop.hive.metastore.HiveMetaStoreClient; -import org.apache.hadoop.hive.metastore.api.FieldSchema; -import org.apache.hadoop.hive.metastore.api.Table; -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.DataTypeLoader; -import org.apache.thrift.TException; - -import javax.sql.DataSource; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Types; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedList; -import java.util.Map; - -/** - * Hive meta data loader. - */ -public final class HiveMetaDataLoader implements DialectMetaDataLoader { - - private static final String HIVE_METASTORE_URIS = "hive.metastore.uris"; - - @Override - public Collection load(final MetaDataLoaderMaterial material) throws SQLException { - HiveMetaStoreClient storeClient = null; - try { - // TODO Support set hive.metastore uris when register storage unit. - HiveConf hiveConf = new HiveConf(); - hiveConf.set(HIVE_METASTORE_URIS, ""); - storeClient = new HiveMetaStoreClient(hiveConf); - return Collections.singletonList(new SchemaMetaData(material.getDefaultSchemaName(), - getTableMetaData(storeClient.getAllTables(material.getDefaultSchemaName()), storeClient, material))); - } catch (final TException ignored) { - throw new SQLException(); - } finally { - if (null != storeClient) { - storeClient.close(); - } - } - } - - private Collection getTableMetaData(final Collection tables, final HiveMetaStoreClient storeClient, final MetaDataLoaderMaterial material) throws TException, SQLException { - Map dataTypes = getDataType(material.getDataSource()); - Collection result = new LinkedList<>(); - for (String each : tables) { - result.add(new TableMetaData(each, getColumnMetaData(storeClient.getTable(material.getDefaultSchemaName(), each), dataTypes), Collections.emptyList(), Collections.emptyList())); - } - return result; - } - - private Map getDataType(final DataSource dataSource) throws SQLException { - try ( - Connection connection = dataSource.getConnection()) { - return new DataTypeLoader().load(connection.getMetaData(), getType()); - } - } - - private Collection getColumnMetaData(final Table table, final Map dataTypes) { - Collection result = new LinkedList<>(); - for (FieldSchema each : table.getSd().getCols()) { - result.add(new ColumnMetaData(each.getName(), null == dataTypes.get(each.getType()) ? Types.VARCHAR : dataTypes.get(each.getType()), - false, false, false, false, false, false)); - } - return result; - } - - @Override - public String getDatabaseType() { - return "Hive"; - } -} diff --git a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/proxy-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/proxy-config.json index 0fe58c75c428c6..0c7ccaecd87c15 100644 --- a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/proxy-config.json +++ b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/proxy-config.json @@ -6,5 +6,9 @@ { "condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.standalone.jdbc.JDBCRepository"}, "interfaces":["java.sql.Connection"] + }, + { + "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, + "interfaces":["org.apache.hive.service.rpc.thrift.TCLIService$Iface"] } ] \ 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/reflect-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/reflect-config.json index 0aab93c80af8ea..2fe1dce292dd67 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.mode.manager.standalone.StandaloneContextManagerBuilder"}, "name":"JdkLogger" }, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, - "name":"[B" -}, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.standalone.jdbc.sql.JDBCRepositorySQLLoader"}, "name":"[Lcom.fasterxml.jackson.databind.deser.BeanDeserializerModifier;" @@ -15,54 +11,6 @@ "condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.standalone.jdbc.sql.JDBCRepositorySQLLoader"}, "name":"[Lcom.fasterxml.jackson.databind.ser.BeanSerializerModifier;" }, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, - "name":"[Lcom.github.dockerjava.api.model.Bind;" -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, - "name":"[Lcom.github.dockerjava.api.model.Capability;" -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, - "name":"[Lcom.github.dockerjava.api.model.Device;" -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, - "name":"[Lcom.github.dockerjava.api.model.ExposedPort;" -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, - "name":"[Lcom.github.dockerjava.api.model.Link;" -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, - "name":"[Lcom.github.dockerjava.api.model.LxcConf;" -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, - "name":"[Lcom.github.dockerjava.api.model.PortBinding;" -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, - "name":"[Lcom.github.dockerjava.api.model.Ports$Binding;" -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, - "name":"[Lcom.github.dockerjava.api.model.Ulimit;" -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, - "name":"[Lcom.github.dockerjava.api.model.Volume;" -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, - "name":"[Lcom.github.dockerjava.api.model.VolumeBind;" -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, - "name":"[Lcom.github.dockerjava.api.model.VolumeRW;" -}, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, "name":"[Lcom.github.dockerjava.api.model.VolumesFrom;" @@ -111,10 +59,6 @@ "condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.standalone.jdbc.JDBCRepository"}, "name":"[Ljava.sql.Statement;" }, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, - "name":"[Lorg.testcontainers.shaded.com.fasterxml.jackson.databind.deser.BeanDeserializerModifier;" -}, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.util.yaml.YamlEngine"}, "name":"java.util.Properties", @@ -408,6 +352,14 @@ "condition":{"typeReachable":"org.apache.shardingsphere.infra.database.core.type.DatabaseTypeFactory"}, "name":"org.apache.shardingsphere.infra.database.h2.type.H2DatabaseType" }, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry"}, + "name":"org.apache.shardingsphere.infra.database.hive.metadata.database.HiveDatabaseMetaData" +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.infra.database.core.type.DatabaseTypeFactory"}, + "name":"org.apache.shardingsphere.infra.database.hive.type.HiveDatabaseType" +}, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.database.core.type.DatabaseTypeFactory"}, "name":"org.apache.shardingsphere.infra.database.mariadb.type.MariaDBDatabaseType" @@ -587,12 +539,12 @@ "name":"org.apache.shardingsphere.infra.util.eventbus.EventSubscriber" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.event.subsciber.DeliverEventSubscriberRegistry$$Lambda/0x00007f30ffc53708"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.event.subsciber.DeliverEventSubscriberRegistry$$Lambda/0x00007f793bd42c70"}, "name":"org.apache.shardingsphere.infra.util.eventbus.EventSubscriber", "queryAllDeclaredMethods":true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f30ffc643b0"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f793bd55f58"}, "name":"org.apache.shardingsphere.infra.util.eventbus.EventSubscriber", "queryAllDeclaredMethods":true }, @@ -906,7 +858,7 @@ "name":"org.apache.shardingsphere.mask.yaml.config.rule.YamlMaskTableRuleConfigurationCustomizer" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.event.subsciber.DeliverEventSubscriberRegistry$$Lambda/0x00007f30ffc53708"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.event.subsciber.DeliverEventSubscriberRegistry$$Lambda/0x00007f793bd42c70"}, "name":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.deliver.DeliverQualifiedDataSourceSubscriber", "queryAllDeclaredMethods":true }, @@ -916,42 +868,42 @@ "methods":[{"name":"cleanCache","parameterTypes":["org.apache.shardingsphere.mode.event.dispatch.DispatchEvent"] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f30ffc643b0"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f793bd55f58"}, "name":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.CacheEvictedSubscriber", "queryAllDeclaredMethods":true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f30ffc643b0"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f793bd55f58"}, "name":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.ComputeNodeOnlineSubscriber", "queryAllDeclaredMethods":true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f30ffc643b0"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f793bd55f58"}, "name":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.DatabaseChangedSubscriber", "queryAllDeclaredMethods":true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f30ffc643b0"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f793bd55f58"}, "name":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.GlobalRuleConfigurationEventSubscriber", "queryAllDeclaredMethods":true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f30ffc643b0"}, - "name":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.ListenerAssistedMetaDataChangedSubscriber", + "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f793bd55f58"}, + "name":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.ListenerAssistedSubscriber", "queryAllDeclaredMethods":true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f30ffc643b0"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f793bd55f58"}, "name":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.ProcessListChangedSubscriber", "queryAllDeclaredMethods":true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f30ffc643b0"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f793bd55f58"}, "name":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.PropertiesEventSubscriber", "queryAllDeclaredMethods":true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f30ffc643b0"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f793bd55f58"}, "name":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.QualifiedDataSourceSubscriber", "queryAllDeclaredMethods":true }, @@ -960,26 +912,26 @@ "name":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.ResourceMetaDataChangedSubscriber" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f30ffc643b0"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f793bd55f58"}, "name":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.ResourceMetaDataChangedSubscriber", "queryAllDeclaredMethods":true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.listener.MetaDataChangedListener$$Lambda/0x00007f30ffc6a438"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.listener.MetaDataChangedListener$$Lambda/0x00007f793bd5bea0"}, "name":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.ResourceMetaDataChangedSubscriber" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f30ffc643b0"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f793bd55f58"}, "name":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.RuleItemChangedSubscriber", "queryAllDeclaredMethods":true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f30ffc643b0"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f793bd55f58"}, "name":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.StateChangedSubscriber", "queryAllDeclaredMethods":true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f30ffc643b0"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry$$Lambda/0x00007f793bd55f58"}, "name":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.StorageUnitEventSubscriber", "queryAllDeclaredMethods":true }, @@ -1544,6 +1496,11 @@ "condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.core.database.cache.ParseTreeCacheBuilder"}, "name":"org.apache.shardingsphere.sql.parser.core.database.cache.ParseTreeCacheLoader" }, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.core.database.visitor.SQLStatementVisitorFactory"}, + "name":"org.apache.shardingsphere.sql.parser.hive.visitor.statement.HiveStatementVisitorFacade", + "methods":[{"name":"","parameterTypes":[] }] +}, { "condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.core.SQLParserFactory"}, "name":"org.apache.shardingsphere.sql.parser.mysql.parser.MySQLLexer", @@ -1669,6 +1626,16 @@ "name":"org.apache.shardingsphere.sql.parser.statement.clickhouse.dml.ClickHouseSelectStatement", "methods":[{"name":"","parameterTypes":[] }] }, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.infra.binder.statement.dml.DeleteStatementBinder"}, + "name":"org.apache.shardingsphere.sql.parser.statement.hive.dml.HiveDeleteStatement", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement"}, + "name":"org.apache.shardingsphere.sql.parser.statement.hive.dml.HiveSelectStatement", + "methods":[{"name":"","parameterTypes":[] }] +}, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.binder.statement.dml.DeleteStatementBinder"}, "name":"org.apache.shardingsphere.sql.parser.statement.mysql.dml.MySQLDeleteStatement", 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 0fb0083bb54f10..d6d52ef2d371c4 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 @@ -108,9 +108,6 @@ }, { "condition":{"typeReachable":"org.apache.shardingsphere.encrypt.algorithm.standard.AESEncryptAlgorithm"}, "pattern":"\\QMETA-INF/services/java.net.spi.URLStreamHandlerProvider\\E" - }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, - "pattern":"\\QMETA-INF/services/java.nio.channels.spi.SelectorProvider\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.standalone.jdbc.JDBCRepository"}, "pattern":"\\QMETA-INF/services/java.time.zone.ZoneRulesProvider\\E" @@ -213,9 +210,6 @@ }, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, "pattern":"\\QMETA-INF/services/org.testcontainers.core.CreateContainerCmdModifier\\E" - }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, - "pattern":"\\QMETA-INF/services/org.testcontainers.dockerclient.DockerClientProviderStrategy\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.transaction.base.seata.at.SeataATShardingSphereTransactionManager"}, "pattern":"\\Q\\E" @@ -231,15 +225,9 @@ }, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, "pattern":"\\Qcom/clickhouse/client/internal/jpountz/util/linux/amd64/liblz4-java.so\\E" - }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, - "pattern":"\\Qcom/github/dockerjava/zerodep/shaded/org/apache/hc/client5/version.properties\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, "pattern":"\\Qcontainer-license-acceptance.txt\\E" - }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, - "pattern":"\\Qdocker-java.properties\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.cluster.etcd.EtcdRepository"}, "pattern":"\\Qjndi.properties\\E" @@ -249,9 +237,6 @@ }, { "condition":{"typeReachable":"org.apache.shardingsphere.transaction.base.seata.at.SeataATShardingSphereTransactionManager"}, "pattern":"\\Qlib/sqlparser/druid.jar\\E" - }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, - "pattern":"\\Qmozilla/public-suffix-list.txt\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, "pattern":"\\Qorg/apache/hc/core5/version.properties\\E" @@ -2733,6 +2718,9 @@ }, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.url.classpath.ClassPathURLLoader"}, "pattern":"\\Qtest-native/yaml/databases/clickhouse.yaml\\E" + }, { + "condition":{"typeReachable":"org.apache.shardingsphere.infra.url.classpath.ClassPathURLLoader"}, + "pattern":"\\Qtest-native/yaml/databases/hive.yaml\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.url.classpath.ClassPathURLLoader"}, "pattern":"\\Qtest-native/yaml/databases/mysql.yaml\\E" @@ -2775,9 +2763,6 @@ }, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.url.classpath.ClassPathURLLoader"}, "pattern":"\\Qtest-native/yaml/transactions/xa/narayana.yaml\\E" - }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder"}, - "pattern":"\\Qtestcontainers.properties\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.transaction.xa.atomikos.manager.AtomikosTransactionManagerProvider"}, "pattern":"\\Qtransactions-defaults.properties\\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 0f2662cd0a8dc8..a77adeca514764 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 @@ -53,5 +53,30 @@ "condition":{"typeReachable":"org.apache.shardingsphere.infra.util.eventbus.EventBusContext"}, "name":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.StateChangedSubscriber", "methods":[{"name":"renew","parameterTypes":["org.apache.shardingsphere.mode.event.dispatch.state.cluster.ClusterStateEvent"] }] +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.hive.parser.HiveLexer"}, + "name":"org.apache.shardingsphere.sql.parser.hive.parser.HiveLexer", + "methods":[{"name":"","parameterTypes":["org.antlr.v4.runtime.CharStream"] }] +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.hive.parser.HiveParser"}, + "name":"org.apache.shardingsphere.sql.parser.hive.parser.HiveParser", + "methods":[{"name":"","parameterTypes":["org.antlr.v4.runtime.TokenStream"] }] +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.hive.visitor.statement.type.HiveDMLStatementVisitor"}, + "name":"org.apache.shardingsphere.sql.parser.hive.visitor.statement.type.HiveDMLStatementVisitor", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.sql.dialect.statement.hive.dml.HiveInsertStatement"}, + "name":"org.apache.shardingsphere.sql.parser.sql.dialect.statement.hive.dml.HiveInsertStatement", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.statement.hive.dml.HiveInsertStatement"}, + "name":"org.apache.shardingsphere.sql.parser.statement.hive.dml.HiveInsertStatement", + "methods":[{"name":"","parameterTypes":[] }] } ] diff --git a/pom.xml b/pom.xml index 5bef146c830d17..05944448c97513 100644 --- a/pom.xml +++ b/pom.xml @@ -125,7 +125,8 @@ 3.1.0-og 2.4.2 0.6.0-patch5 - 3.1.3 + 4.0.0 + 3.3.5 0.282 4.0.3 @@ -481,153 +482,19 @@ org.apache.hive hive-jdbc ${hive.version} - provided - - - org.glassfish - javax.el - - - com.github.joshelser - dropwizard-metrics-hadoop-metrics2-reporter - - - com.zaxxer - HikariCP-java7 - - - org.slf4j - slf4j-log4j12 - - - org.apache.logging.log4j - log4j-slf4j-impl - - - org.apache.logging.log4j - log4j-1.2-api - - - commons-collections - commons-collections - - - jdk.tools - jdk.tools - - - log4j - log4j - - - org.apache.logging.log4j - log4j-web - - - org.apache.hadoop - hadoop-yarn-server-resourcemanager - - - org.eclipse.jetty - jetty-http - - - org.eclipse.jetty - jetty-rewrite - - - org.eclipse.jetty - jetty-server - - - org.eclipse.jetty - jetty-servlet - - - org.eclipse.jetty - jetty-webapp - - - org.apache.orc - orc-core - - - com.jcraft - jsch - - - jline - jline - - - io.dropwizard.metrics - metrics-core - - - io.dropwizard.metrics - metrics-json - - - io.dropwizard.metrics - metrics-jvm - - - org.apache.ant - ant - - - org.apache.hive - hive-serde - - - co.cask.tephra - tephra-api - - - co.cask.tephra - tephra-core - - - co.cask.tephra - tephra-hbase-compat-1.0 - - - org.eclipse.jetty - jetty-util - - - com.sun.jersey - jersey-servlet - - - org.jruby.joni - joni - - - sqlline - sqlline - - - org.apache.hbase - hbase-metrics - - - org.apache.hbase - hbase-metrics-api - - - com.jolbox - bonecp - - - commons-dbcp - commons-dbcp - - - junit - junit - - + test + + + org.apache.hive + hive-service + ${hive.version} + test + + + org.apache.hadoop + hadoop-client-api + ${hadoop.version} + test com.facebook.presto @@ -1148,7 +1015,8 @@ maven-surefire-plugin false - --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED + + --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED diff --git a/test/native/native-image-filter/extra-filter.json b/test/native/native-image-filter/extra-filter.json index ca2b00516a04f4..b00b88eb2d12e2 100644 --- a/test/native/native-image-filter/extra-filter.json +++ b/test/native/native-image-filter/extra-filter.json @@ -2,14 +2,16 @@ "rules": [ {"includeClasses": "**"}, - {"excludeClasses": "com.sun.crypto.provider.**"}, - {"excludeClasses": "com.sun.org.apache.xerces.internal.jaxp.**"}, + {"excludeClasses": "com.sun.**"}, {"excludeClasses": "java.**"}, {"includeClasses": "java.util.Properties"}, + {"excludeClasses": "javax.script.**"}, {"excludeClasses": "javax.security.auth.x500.**"}, {"excludeClasses": "javax.smartcardio.**"}, + {"excludeClasses": "javax.swing.**"}, {"excludeClasses": "javax.xml.stream.**"}, {"excludeClasses": "jdk.internal.misc.**"}, + {"excludeClasses": "org.w3c.dom.**"}, {"excludeClasses": "sun.misc.**"}, {"excludeClasses": "sun.nio.ch.**"}, {"excludeClasses": "sun.security.**"}, @@ -39,6 +41,8 @@ {"excludeClasses": "net.bytebuddy.**"}, {"excludeClasses": "org.apache.calcite.**"}, {"excludeClasses": "org.apache.commons.logging.**"}, + {"excludeClasses": "org.apache.derby.jdbc.**"}, + {"excludeClasses": "org.apache.hive.**"}, {"excludeClasses": "org.apache.logging.log4j.**"}, {"excludeClasses": "org.apache.log4j.**"}, {"excludeClasses": "org.apache.zookeeper.**"}, diff --git a/test/native/pom.xml b/test/native/pom.xml index 872f6b9741fd04..6afdfbdfc50b7b 100644 --- a/test/native/pom.xml +++ b/test/native/pom.xml @@ -131,6 +131,17 @@ using Seata Client under GraalVM Native Image requires using the version release ${project.version} test + + org.apache.shardingsphere + shardingsphere-infra-database-hive + ${project.version} + + + org.apache.shardingsphere + shardingsphere-parser-sql-hive + ${project.version} + test + org.awaitility @@ -163,6 +174,71 @@ using Seata Client under GraalVM Native Image requires using the version release http test + + org.apache.hive + hive-jdbc + test + + + org.apache.hive + hive-service + test + + + org.apache.logging.log4j + log4j-slf4j-impl + + + org.slf4j + slf4j-reload4j + + + org.apache.logging.log4j + log4j-api + + + org.antlr + antlr4-runtime + + + org.codehaus.janino + commons-compiler + + + org.apache.commons + commons-dbcp2 + + + commons-io + commons-io + + + commons-lang + commons-lang + + + org.apache.commons + commons-pool2 + + + org.codehaus.janino + janino + + + com.fasterxml.woodstox + woodstox-core + + + org.bouncycastle + bcprov-jdk15on + + + + + org.apache.hadoop + hadoop-client-api + test + org.testcontainers junit-jupiter diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/TestShardingService.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/TestShardingService.java index 762ab420aa3ff4..395515a37272a1 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/TestShardingService.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/TestShardingService.java @@ -119,6 +119,28 @@ public void processSuccessInClickHouse() throws SQLException { assertThat(addressRepository.selectAll(), equalTo(Collections.emptyList())); } + /** + * Process success in Hive. + * Hive has not fully supported BEGIN, COMMIT, and ROLLBACK. Refer to Hive Transactions. + * So ShardingSphere should not use {@link OrderItemRepository#assertRollbackWithTransactions()} + * TODO It seems that there is no way to force all HiveServer2 insert statements to complete. + * This results in the following assertion always failing, which needs to be investigated on the apache/hive side. + *
+     * insertDataInHive();
+     * assertThat(addressRepository.selectAll(),
+     *     equalTo(LongStream.range(1L, 11L).mapToObj(each -> new Address(each, "address_test_" + each)).collect(Collectors.toList())));
+     * 
+ * TODO It is currently not convenient to operate on the `t_order` and `t_order_item` tables because + * {@link org.apache.hive.jdbc.HiveStatement} does not implement {@link Statement#getGeneratedKeys()} + * + * @throws SQLException An exception that provides information on a database access error or other errors. + */ + public void processSuccessInHive() throws SQLException { + insertDataInHive(); + deleteDataInHive(); + assertThat(addressRepository.selectAll(), equalTo(Collections.emptyList())); + } + /** * Insert data. * @@ -151,6 +173,20 @@ public Collection insertData(final int autoGeneratedKeys) throws SQLExcept return result; } + /** + * Insert data in Hive. + */ + public void insertDataInHive() { + LongStream.range(1L, 11L).forEach(action -> { + Address address = new Address(action, "address_test_" + action); + try { + addressRepository.insert(address); + } catch (final SQLException ex) { + throw new RuntimeException(ex); + } + }); + } + /** * Delete data. * @@ -181,6 +217,18 @@ public void deleteDataInClickHouse(final Collection orderIds) throws SQLEx } } + /** + * Delete data in Hive. + * + * @throws SQLException An exception that provides information on a database access error or other errors. + */ + public void deleteDataInHive() throws SQLException { + long count = 1L; + for (int i = 1; i <= 10; i++) { + addressRepository.deleteInHive(count++); + } + } + /** * Clean environment. * diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/AddressRepository.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/AddressRepository.java index 182913898cd479..ce0712efed868b 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/AddressRepository.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/AddressRepository.java @@ -70,6 +70,25 @@ public void createTableInSQLServer() throws SQLException { } } + /** + * create table t_address if not exists in Hive. + * + * @throws SQLException SQL exception + */ + public void createTableIfNotExistsInHive() throws SQLException { + String sql = "CREATE TABLE IF NOT EXISTS t_address\n" + + "(\n" + + " address_id BIGINT NOT NULL,\n" + + " address_name VARCHAR(100) NOT NULL,\n" + + " PRIMARY KEY (address_id) disable novalidate\n" + + ") CLUSTERED BY (address_id) INTO 2 BUCKETS STORED AS ORC TBLPROPERTIES ('transactional'='true')"; + try ( + Connection connection = dataSource.getConnection(); + Statement statement = connection.createStatement()) { + statement.executeUpdate(sql); + } + } + /** * drop table t_address. * @@ -133,6 +152,22 @@ public void delete(final Long id) throws SQLException { } } + /** + * delete by id. + * + * @param id id + * @throws SQLException SQL exception + */ + public void deleteInHive(final Long id) throws SQLException { + String sql = "DELETE FROM t_address WHERE address_id=?"; + try ( + Connection connection = dataSource.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement(sql)) { + preparedStatement.setLong(1, id); + preparedStatement.executeUpdate(); + } + } + /** * delete by id in ClickHouse. * diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/OrderItemRepository.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/OrderItemRepository.java index b53071fb09087f..d9b32cbc462284 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/OrderItemRepository.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/OrderItemRepository.java @@ -125,6 +125,28 @@ public void createTableIfNotExistsInClickHouse() throws SQLException { } } + /** + * create table if not exists in Hive. + * Hive does not support `AUTO_INCREMENT`, refer to HIVE-6905 . + * + * @throws SQLException SQL exception + */ + public void createTableIfNotExistsInHive() throws SQLException { + String sql = "CREATE TABLE IF NOT EXISTS t_order_item\n" + + "(order_item_id BIGINT,\n" + + " order_id BIGINT NOT NULL,\n" + + " user_id INT NOT NULL,\n" + + " phone VARCHAR(50),\n" + + " status VARCHAR(50),\n" + + " PRIMARY KEY (order_item_id) disable novalidate\n" + + ") CLUSTERED BY (order_item_id) INTO 2 BUCKETS STORED AS ORC TBLPROPERTIES ('transactional'='true')"; + try ( + Connection connection = dataSource.getConnection(); + Statement statement = connection.createStatement()) { + statement.executeUpdate(sql); + } + } + /** * drop table. * diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/OrderRepository.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/OrderRepository.java index 7cded2baf10f56..b595b672190ba4 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/OrderRepository.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/OrderRepository.java @@ -122,6 +122,29 @@ public void createTableIfNotExistsInClickHouse() throws SQLException { } } + /** + * create table in Hive. + * Hive does not support `AUTO_INCREMENT`, refer to HIVE-6905 . + * + * @throws SQLException SQL exception + */ + public void createTableIfNotExistsInHive() throws SQLException { + String sql = "CREATE TABLE IF NOT EXISTS t_order\n" + + "(\n" + + " order_id BIGINT,\n" + + " order_type INT,\n" + + " user_id INT NOT NULL,\n" + + " address_id BIGINT NOT NULL,\n" + + " status VARCHAR(50),\n" + + " PRIMARY KEY (order_id) disable novalidate\n" + + ") CLUSTERED BY (order_id) INTO 2 BUCKETS STORED AS ORC TBLPROPERTIES ('transactional'='true')"; + try ( + Connection connection = dataSource.getConnection(); + Statement statement = connection.createStatement()) { + statement.executeUpdate(sql); + } + } + /** * drop table. * TODO There is a bug in this function in shadow's unit test and requires additional fixes. diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/HiveTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/HiveTest.java new file mode 100644 index 00000000000000..0c21ab91fcfe0c --- /dev/null +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/HiveTest.java @@ -0,0 +1,137 @@ +/* + * 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.test.natived.jdbc.commons.TestShardingService; +import org.awaitility.Awaitility; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledInNativeImage; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; +import org.testcontainers.utility.DockerImageName; + +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.Properties; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +@SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection"}) +@EnabledInNativeImage +@Testcontainers +class HiveTest { + + @SuppressWarnings("resource") + @Container + public static final GenericContainer CONTAINER = new GenericContainer<>(DockerImageName.parse("apache/hive:4.0.0")) + .withEnv("SERVICE_NAME", "hiveserver2") + .withExposedPorts(10000, 10002); + + private static final String SYSTEM_PROP_KEY_PREFIX = "fixture.test-native.yaml.database.hive."; + + // Due to https://issues.apache.org/jira/browse/HIVE-28317 , the `initFile` parameter of HiveServer2 JDBC Driver must be an absolute path. + private static final String ABSOLUTE_PATH = Paths.get("src/test/resources/test-native/sql/test-native-databases-hive.sql").toAbsolutePath().normalize().toString(); + + private String jdbcUrlPrefix; + + private TestShardingService testShardingService; + + @BeforeAll + static void beforeAll() { + assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url"), is(nullValue())); + assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url"), is(nullValue())); + assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url"), is(nullValue())); + } + + @AfterAll + static void afterAll() { + System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url"); + System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url"); + System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url"); + } + + /** + * TODO Need to fix `shardingsphere-parser-sql-hive` module to use {@link TestShardingService#cleanEnvironment()} + * after {@link TestShardingService#processSuccessInHive()}. + * + * @throws SQLException An exception that provides information on a database access error or other errors. + */ + @Test + void assertShardingInLocalTransactions() throws SQLException { + jdbcUrlPrefix = "jdbc:hive2://localhost:" + CONTAINER.getMappedPort(10000) + "/"; + DataSource dataSource = createDataSource(); + testShardingService = new TestShardingService(dataSource); + testShardingService.processSuccessInHive(); + } + + /** + * TODO Need to fix `shardingsphere-parser-sql-hive` module to use `initEnvironment()` before {@link TestShardingService#processSuccessInHive()}. + * + * @throws SQLException An exception that provides information on a database access error or other errors. + */ + @SuppressWarnings("unused") + private void initEnvironment() throws SQLException { + testShardingService.getOrderRepository().createTableIfNotExistsInHive(); + testShardingService.getOrderItemRepository().createTableIfNotExistsInHive(); + testShardingService.getAddressRepository().createTableIfNotExistsInHive(); + testShardingService.getOrderRepository().truncateTable(); + testShardingService.getOrderItemRepository().truncateTable(); + testShardingService.getAddressRepository().truncateTable(); + } + + private Connection openConnection() throws SQLException { + Properties props = new Properties(); + return DriverManager.getConnection(jdbcUrlPrefix, props); + } + + private DataSource createDataSource() throws SQLException { + Awaitility.await().atMost(Duration.ofMinutes(1L)).ignoreExceptions().until(() -> { + openConnection().close(); + return true; + }); + try ( + Connection connection = openConnection(); + Statement statement = connection.createStatement()) { + statement.execute("set metastore.compactor.initiator.on=true"); + statement.execute("set metastore.compactor.cleaner.on=true"); + statement.execute("set metastore.compactor.worker.threads=5"); + statement.executeUpdate("CREATE DATABASE demo_ds_0"); + statement.executeUpdate("CREATE DATABASE demo_ds_1"); + statement.executeUpdate("CREATE DATABASE demo_ds_2"); + } + HikariConfig config = new HikariConfig(); + config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver"); + config.setJdbcUrl("jdbc:shardingsphere:classpath:test-native/yaml/databases/hive.yaml?placeholder-type=system_props"); + System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url", jdbcUrlPrefix + "demo_ds_0" + ";initFile=" + ABSOLUTE_PATH); + System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url", jdbcUrlPrefix + "demo_ds_1" + ";initFile=" + ABSOLUTE_PATH); + System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url", jdbcUrlPrefix + "demo_ds_2" + ";initFile=" + ABSOLUTE_PATH); + return new HikariDataSource(config); + } +} diff --git a/infra/database/type/hive/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.metadata.data.loader.DialectMetaDataLoader b/test/native/src/test/resources/META-INF/native-image/io.grpc/grpc-netty-shaded/native-image.properties similarity index 57% rename from infra/database/type/hive/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.metadata.data.loader.DialectMetaDataLoader rename to test/native/src/test/resources/META-INF/native-image/io.grpc/grpc-netty-shaded/native-image.properties index 6522f228700754..9178449a17048a 100644 --- a/infra/database/type/hive/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.metadata.data.loader.DialectMetaDataLoader +++ b/test/native/src/test/resources/META-INF/native-image/io.grpc/grpc-netty-shaded/native-image.properties @@ -14,5 +14,12 @@ # See the License for the specific language governing permissions and # limitations under the License. # - -org.apache.shardingsphere.infra.database.hive.metadata.data.loader.HiveMetaDataLoader +# TODO This file exists to address https://github.com/grpc/grpc-java/issues/10601 . +Args=--initialize-at-run-time=\ + io.grpc.netty.shaded.io.netty.channel.ChannelHandlerMask,\ + io.grpc.netty.shaded.io.netty.channel.nio.AbstractNioChannel,\ + io.grpc.netty.shaded.io.netty.channel.socket.nio.SelectorProviderUtil,\ + io.grpc.netty.shaded.io.netty.util.concurrent.DefaultPromise,\ + io.grpc.netty.shaded.io.netty.util.internal.MacAddressUtil,\ + io.grpc.netty.shaded.io.netty.util.internal.SystemPropertyUtil,\ + io.grpc.netty.shaded.io.netty.util.NetUtilInitializations diff --git a/test/native/src/test/resources/test-native/sql/test-native-databases-hive.sql b/test/native/src/test/resources/test-native/sql/test-native-databases-hive.sql new file mode 100644 index 00000000000000..d23900f7d799c0 --- /dev/null +++ b/test/native/src/test/resources/test-native/sql/test-native-databases-hive.sql @@ -0,0 +1,54 @@ +-- +-- 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. +-- + + +-- TODO To execute SQL like `DELETE FROM t_address WHERE address_id=?`, we always need to execute the following Hive Session-level SQL in the current `javax.sql.DataSource`. +-- `shardingsphere-parser-sql-hive` module does not support `CREATE`, `SET`, `TRUNCATE` statements yet. +set hive.support.concurrency=true; +set hive.exec.dynamic.partition.mode=nonstrict; +set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager; + +CREATE TABLE IF NOT EXISTS t_order +( + order_id BIGINT, + order_type INT, + user_id INT NOT NULL, + address_id BIGINT NOT NULL, + status VARCHAR(50), + PRIMARY KEY (order_id) disable novalidate +) CLUSTERED BY (order_id) INTO 2 BUCKETS STORED AS ORC TBLPROPERTIES ('transactional' = 'true'); + +CREATE TABLE IF NOT EXISTS t_order_item +( + order_item_id BIGINT, + order_id BIGINT NOT NULL, + user_id INT NOT NULL, + phone VARCHAR(50), + status VARCHAR(50), + PRIMARY KEY (order_item_id) disable novalidate +) CLUSTERED BY (order_item_id) INTO 2 BUCKETS STORED AS ORC TBLPROPERTIES ('transactional' = 'true'); + +CREATE TABLE IF NOT EXISTS t_address +( + address_id BIGINT NOT NULL, + address_name VARCHAR(100) NOT NULL, + PRIMARY KEY (address_id) disable novalidate +) CLUSTERED BY (address_id) INTO 2 BUCKETS STORED AS ORC TBLPROPERTIES ('transactional' = 'true'); + +TRUNCATE TABLE t_order; +TRUNCATE TABLE t_order_item; +TRUNCATE TABLE t_address; diff --git a/test/native/src/test/resources/test-native/yaml/databases/hive.yaml b/test/native/src/test/resources/test-native/yaml/databases/hive.yaml new file mode 100644 index 00000000000000..c44cd303bb3bc5 --- /dev/null +++ b/test/native/src/test/resources/test-native/yaml/databases/hive.yaml @@ -0,0 +1,72 @@ +# +# 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. +# + +mode: + type: Standalone + repository: + type: JDBC + +dataSources: + ds_0: + dataSourceClassName: com.zaxxer.hikari.HikariDataSource + driverClassName: org.apache.hive.jdbc.HiveDriver + jdbcUrl: $${fixture.test-native.yaml.database.hive.ds0.jdbc-url::} + ds_1: + dataSourceClassName: com.zaxxer.hikari.HikariDataSource + driverClassName: org.apache.hive.jdbc.HiveDriver + jdbcUrl: $${fixture.test-native.yaml.database.hive.ds1.jdbc-url::} + ds_2: + dataSourceClassName: com.zaxxer.hikari.HikariDataSource + driverClassName: org.apache.hive.jdbc.HiveDriver + jdbcUrl: $${fixture.test-native.yaml.database.hive.ds2.jdbc-url::} + +rules: +- !SHARDING + tables: + t_order: + actualDataNodes: + keyGenerateStrategy: + column: order_id + keyGeneratorName: snowflake + t_order_item: + actualDataNodes: + 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.jdbc.commons.algorithm.ClassBasedInlineShardingAlgorithmFixture + keyGenerators: + snowflake: + type: SNOWFLAKE + auditors: + sharding_key_required_auditor: + type: DML_SHARDING_CONDITIONS + +- !BROADCAST + tables: + - t_address + +props: + sql-show: false