This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-paimon-presto.git
The following commit(s) were added to refs/heads/main by this push:
new 15c624d PrestoDB use inject (#16)
15c624d is described below
commit 15c624d25747169a52c88e131c8e6449b23e7f0b
Author: humengyu <[email protected]>
AuthorDate: Wed Nov 22 12:04:40 2023 +0800
PrestoDB use inject (#16)
---
README.md | 104 +++++++++++++++++++++
paimon-presto-0.236/pom.xml | 50 ++++++----
paimon-presto-0.236/src/main/assembly/paimon.xml | 32 +++++++
.../org/apache/paimon/presto/PrestoConnector.java | 11 +--
paimon-presto-0.268/pom.xml | 26 ++----
paimon-presto-0.268/src/main/assembly/paimon.xml | 32 +++++++
.../org/apache/paimon/presto/PrestoConnector.java | 11 +--
paimon-presto-0.273/pom.xml | 26 ++----
paimon-presto-0.273/src/main/assembly/paimon.xml | 32 +++++++
paimon-presto-common/pom.xml | 82 ++++++++--------
...restoMetadataFactory.java => PaimonConfig.java} | 43 ++++++---
...MetadataFactory.java => PaimonConnectorId.java} | 39 +++++---
.../org/apache/paimon/presto/PaimonModule.java | 77 +++++++++++++++
.../org/apache/paimon/presto/PrestoConnector.java | 11 +--
.../apache/paimon/presto/PrestoConnectorBase.java | 9 +-
.../paimon/presto/PrestoConnectorFactory.java | 42 +++++++--
.../org/apache/paimon/presto/PrestoMetadata.java | 3 +
17 files changed, 485 insertions(+), 145 deletions(-)
diff --git a/README.md b/README.md
index d28cacd..8d04072 100644
--- a/README.md
+++ b/README.md
@@ -5,3 +5,107 @@ This repository is Presto Connector for the [Apache
Paimon](https://paimon.apach
## About
Apache Paimon is an open source project of [The Apache Software
Foundation](https://apache.org/) (ASF).
+
+## Getting Started
+
+### Build
+
+```bash
+mvn clean install -DskipTests
+```
+
+During the packaging process, you may encounter the following errors:
+
+```
+[ERROR] Failed to execute goal on project paimon-presto: Could not resolve
dependencies for project org.apache.paimon:paimon-presto:pom:0.6-SNAPSHOT: The
following artifacts could not be resolved:
org.apache.paimon:paimon-bundle:jar:0.6-SNAPSHOT (absent): Could not find
artifact org.apache.paimon:paimon-bundle:jar:0.6-SNAPSHOT in xxx
+```
+
+You can resolve the packaging issue by adding the following Maven repository
addresses to your `settings.xml` or to the `pom.xml` of the current project:
+
+```xml
+<repositories>
+ <repository>
+ <id>apache-releases</id>
+ <name>apache releases</name>
+ <url>https://repository.apache.org/content/repositories/releases/</url>
+ </repository>
+ <repository>
+ <id>apache-snapshots</id>
+ <name>apache snapshots</name>
+
<url>https://repository.apache.org/content/repositories/snapshots/</url>
+ </repository>
+</repositories>
+```
+
+After the packaging is complete, you can choose the corresponding connector
based on your own Presto version:
+
+| Version | Package
|
+|-----------------|-------------------------------------------------------------------------------|
+| [0.236, 0.268) |
`./paimon-presto-0.236/target/paimon-presto-0.236-0.6-SNAPSHOT-plugin.tar.gz` |
+| [0.268, 0.273) |
`./paimon-presto-0.268/target/paimon-presto-0.268-0.6-SNAPSHOT-plugin.tar.gz` |
+| [0.273, latest] |
`./paimon-presto-0.273/target/paimon-presto-0.273-0.6-SNAPSHOT-plugin.tar.gz` |
+
+Of course, we also support different versions of Hive and Hadoop. But note
that we utilize
+Presto-shaded versions of Hive and Hadoop packages to address dependency
conflicts.
+You can check the following two links to select the appropriate versions of
Hive and Hadoop:
+
+[hadoop-apache2](https://mvnrepository.com/artifact/com.facebook.presto.hadoop/hadoop-apache2)
+
+[hive-apache](https://mvnrepository.com/artifact/com.facebook.presto.hive/hive-apache)
+
+Both Hive 2 and 3, as well as Hadoop 2 and 3, are supported.
+
+For example, if your presto version is 0.274, hive and hadoop version is 2.x,
you could run:
+
+```bash
+mvn clean install -DskipTests -am -pl paimon-presto-0.273
-Dpresto.version=0.274 -Dhadoop.apache2.version=2.7.4-9
-Dhive.apache.version=1.2.2-2
+```
+
+### Install Paimon Connector
+
+```bash
+tar -zxf
paimon-presto-${PRESTO_VERSION}/target/paimon-presto-${PRESTO_VERSION}-${PAIMON_VERSION}-plugin.tar.gz
-C ${PRESTO_HOME}/plugin
+```
+
+Note that, the variable `PRESTO_VERSION` is module name, must be one of 0.236,
0.268, 0.273.
+
+### Configuration
+
+```bash
+cd ${PRESTO_HOME}
+mkdir -p etc/catalog
+```
+
+Query FileSystem table:
+
+```bash
+vim etc/catalog/paimon.properties
+```
+
+and set the following config:
+
+```properties
+connector.name=paimon
+# set your filesystem path, like hdfs://namenode01:8020/path
+warehouse=${YOUR_FS_PATH}
+```
+
+Query HiveCatalog table:
+
+```bash
+vim etc/catalog/paimon.properties
+```
+
+and set the following config:
+
+```properties
+connector.name=paimon
+# set your filesystem path, like hdfs://namenode01:8020/path
+warehouse=${YOUR_FS_PATH}
+metastore=hive
+uri=thrift://${YOUR_HIVE_METASTORE}:9083
+```
+
+
+
+
diff --git a/paimon-presto-0.236/pom.xml b/paimon-presto-0.236/pom.xml
index ee0857e..9733a0d 100644
--- a/paimon-presto-0.236/pom.xml
+++ b/paimon-presto-0.236/pom.xml
@@ -35,6 +35,7 @@ under the License.
<presto.version>0.236</presto.version>
<hadoop.apache2.version>2.7.4-9</hadoop.apache2.version>
<slf4j.version>1.7.25</slf4j.version>
+ <airlift.version>0.191</airlift.version>
</properties>
<dependencies>
@@ -43,6 +44,29 @@ under the License.
<artifactId>paimon-presto-common</artifactId>
<version>${project.version}</version>
</dependency>
+
+ <!-- presto 0.236 use lower airlift version -->
+ <dependency>
+ <groupId>com.facebook.airlift</groupId>
+ <artifactId>configuration</artifactId>
+ <version>${airlift.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.facebook.airlift</groupId>
+ <artifactId>bootstrap</artifactId>
+ <version>${airlift.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.facebook.airlift</groupId>
+ <artifactId>json</artifactId>
+ <version>${airlift.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
<dependency>
<groupId>com.facebook.presto</groupId>
<artifactId>presto-spi</artifactId>
@@ -71,13 +95,6 @@ under the License.
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>com.facebook.presto.hadoop</groupId>
- <artifactId>hadoop-apache2</artifactId>
- <version>${hadoop.apache2.version}</version>
- <scope>provided</scope>
- </dependency>
-
<dependency>
<groupId>com.facebook.presto</groupId>
<artifactId>presto-main</artifactId>
@@ -120,22 +137,19 @@ under the License.
<build>
<plugins>
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-shade-plugin</artifactId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.5.5</version>
+ <configuration>
+ <descriptors>
+ <descriptor>src/main/assembly/paimon.xml</descriptor>
+ </descriptors>
+ </configuration>
<executions>
<execution>
- <id>shade-paimon</id>
<phase>package</phase>
<goals>
- <goal>shade</goal>
+ <goal>attached</goal>
</goals>
- <configuration>
- <artifactSet>
- <includes combine.children="append">
-
<include>org.apache.paimon:paimon-presto-common</include>
- </includes>
- </artifactSet>
- </configuration>
</execution>
</executions>
</plugin>
diff --git a/paimon-presto-0.236/src/main/assembly/paimon.xml
b/paimon-presto-0.236/src/main/assembly/paimon.xml
new file mode 100644
index 0000000..c960607
--- /dev/null
+++ b/paimon-presto-0.236/src/main/assembly/paimon.xml
@@ -0,0 +1,32 @@
+<!--
+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.
+-->
+
+<assembly>
+ <id>plugin</id>
+ <formats>
+ <format>tar.gz</format>
+ </formats>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <dependencySets>
+ <dependencySet>
+ <outputDirectory>paimon</outputDirectory>
+ <scope>runtime</scope>
+ </dependencySet>
+ </dependencySets>
+</assembly>
diff --git
a/paimon-presto-0.236/src/main/java/org/apache/paimon/presto/PrestoConnector.java
b/paimon-presto-0.236/src/main/java/org/apache/paimon/presto/PrestoConnector.java
index 3974ce3..8567cbb 100644
---
a/paimon-presto-0.236/src/main/java/org/apache/paimon/presto/PrestoConnector.java
+++
b/paimon-presto-0.236/src/main/java/org/apache/paimon/presto/PrestoConnector.java
@@ -21,21 +21,20 @@ package org.apache.paimon.presto;
import com.facebook.presto.spi.connector.Connector;
import com.facebook.presto.spi.connector.ConnectorTransactionHandle;
+import javax.inject.Inject;
+
/** Presto {@link Connector}. */
public class PrestoConnector extends PrestoConnectorBase {
private final PrestoTransactionManager transactionManager;
+ @Inject
public PrestoConnector(
PrestoTransactionManager transactionManager,
PrestoSplitManager prestoSplitManager,
PrestoPageSourceProvider prestoPageSourceProvider,
- PrestoMetadataFactory prestoMetadataFactory) {
- super(
- transactionManager,
- prestoSplitManager,
- prestoPageSourceProvider,
- prestoMetadataFactory);
+ PrestoMetadata prestoMetadata) {
+ super(transactionManager, prestoSplitManager,
prestoPageSourceProvider, prestoMetadata);
this.transactionManager = transactionManager;
}
diff --git a/paimon-presto-0.268/pom.xml b/paimon-presto-0.268/pom.xml
index cbe657f..0c92d92 100644
--- a/paimon-presto-0.268/pom.xml
+++ b/paimon-presto-0.268/pom.xml
@@ -70,13 +70,6 @@ under the License.
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>com.facebook.presto.hadoop</groupId>
- <artifactId>hadoop-apache2</artifactId>
- <version>${hadoop.apache2.version}</version>
- <scope>provided</scope>
- </dependency>
-
<dependency>
<groupId>com.facebook.presto</groupId>
<artifactId>presto-main</artifactId>
@@ -119,22 +112,19 @@ under the License.
<build>
<plugins>
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-shade-plugin</artifactId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.5.5</version>
+ <configuration>
+ <descriptors>
+ <descriptor>src/main/assembly/paimon.xml</descriptor>
+ </descriptors>
+ </configuration>
<executions>
<execution>
- <id>shade-paimon</id>
<phase>package</phase>
<goals>
- <goal>shade</goal>
+ <goal>attached</goal>
</goals>
- <configuration>
- <artifactSet>
- <includes combine.children="append">
-
<include>org.apache.paimon:paimon-presto-common</include>
- </includes>
- </artifactSet>
- </configuration>
</execution>
</executions>
</plugin>
diff --git a/paimon-presto-0.268/src/main/assembly/paimon.xml
b/paimon-presto-0.268/src/main/assembly/paimon.xml
new file mode 100644
index 0000000..c960607
--- /dev/null
+++ b/paimon-presto-0.268/src/main/assembly/paimon.xml
@@ -0,0 +1,32 @@
+<!--
+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.
+-->
+
+<assembly>
+ <id>plugin</id>
+ <formats>
+ <format>tar.gz</format>
+ </formats>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <dependencySets>
+ <dependencySet>
+ <outputDirectory>paimon</outputDirectory>
+ <scope>runtime</scope>
+ </dependencySet>
+ </dependencySets>
+</assembly>
diff --git
a/paimon-presto-0.268/src/main/java/org/apache/paimon/presto/PrestoConnector.java
b/paimon-presto-0.268/src/main/java/org/apache/paimon/presto/PrestoConnector.java
index 3974ce3..8567cbb 100644
---
a/paimon-presto-0.268/src/main/java/org/apache/paimon/presto/PrestoConnector.java
+++
b/paimon-presto-0.268/src/main/java/org/apache/paimon/presto/PrestoConnector.java
@@ -21,21 +21,20 @@ package org.apache.paimon.presto;
import com.facebook.presto.spi.connector.Connector;
import com.facebook.presto.spi.connector.ConnectorTransactionHandle;
+import javax.inject.Inject;
+
/** Presto {@link Connector}. */
public class PrestoConnector extends PrestoConnectorBase {
private final PrestoTransactionManager transactionManager;
+ @Inject
public PrestoConnector(
PrestoTransactionManager transactionManager,
PrestoSplitManager prestoSplitManager,
PrestoPageSourceProvider prestoPageSourceProvider,
- PrestoMetadataFactory prestoMetadataFactory) {
- super(
- transactionManager,
- prestoSplitManager,
- prestoPageSourceProvider,
- prestoMetadataFactory);
+ PrestoMetadata prestoMetadata) {
+ super(transactionManager, prestoSplitManager,
prestoPageSourceProvider, prestoMetadata);
this.transactionManager = transactionManager;
}
diff --git a/paimon-presto-0.273/pom.xml b/paimon-presto-0.273/pom.xml
index 0e743ea..6c9cdc2 100644
--- a/paimon-presto-0.273/pom.xml
+++ b/paimon-presto-0.273/pom.xml
@@ -70,13 +70,6 @@ under the License.
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>com.facebook.presto.hadoop</groupId>
- <artifactId>hadoop-apache2</artifactId>
- <version>${hadoop.apache2.version}</version>
- <scope>provided</scope>
- </dependency>
-
<dependency>
<groupId>com.facebook.presto</groupId>
<artifactId>presto-main</artifactId>
@@ -119,22 +112,19 @@ under the License.
<build>
<plugins>
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-shade-plugin</artifactId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.5.5</version>
+ <configuration>
+ <descriptors>
+ <descriptor>src/main/assembly/paimon.xml</descriptor>
+ </descriptors>
+ </configuration>
<executions>
<execution>
- <id>shade-paimon</id>
<phase>package</phase>
<goals>
- <goal>shade</goal>
+ <goal>attached</goal>
</goals>
- <configuration>
- <artifactSet>
- <includes combine.children="append">
-
<include>org.apache.paimon:paimon-presto-common</include>
- </includes>
- </artifactSet>
- </configuration>
</execution>
</executions>
</plugin>
diff --git a/paimon-presto-0.273/src/main/assembly/paimon.xml
b/paimon-presto-0.273/src/main/assembly/paimon.xml
new file mode 100644
index 0000000..c960607
--- /dev/null
+++ b/paimon-presto-0.273/src/main/assembly/paimon.xml
@@ -0,0 +1,32 @@
+<!--
+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.
+-->
+
+<assembly>
+ <id>plugin</id>
+ <formats>
+ <format>tar.gz</format>
+ </formats>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <dependencySets>
+ <dependencySet>
+ <outputDirectory>paimon</outputDirectory>
+ <scope>runtime</scope>
+ </dependencySet>
+ </dependencySets>
+</assembly>
diff --git a/paimon-presto-common/pom.xml b/paimon-presto-common/pom.xml
index dd6d246..d4d8cd5 100644
--- a/paimon-presto-common/pom.xml
+++ b/paimon-presto-common/pom.xml
@@ -36,9 +36,54 @@ under the License.
<properties>
<presto.version>0.273</presto.version>
<hadoop.apache2.version>2.7.4-9</hadoop.apache2.version>
+ <hive.apache.version>1.2.2-2</hive.apache.version>
+ <airlift.version>0.205</airlift.version>
+ <libthrift.version>0.9.3</libthrift.version>
</properties>
<dependencies>
+
+ <!-- see
https://mvnrepository.com/artifact/com.facebook.presto.hadoop/hadoop-apache2 -->
+ <dependency>
+ <groupId>com.facebook.presto.hadoop</groupId>
+ <artifactId>hadoop-apache2</artifactId>
+ <version>${hadoop.apache2.version}</version>
+ </dependency>
+
+ <!-- see
https://mvnrepository.com/artifact/com.facebook.presto.hive/hive-apache -->
+ <dependency>
+ <groupId>com.facebook.presto.hive</groupId>
+ <artifactId>hive-apache</artifactId>
+ <version>${hive.apache.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.thrift</groupId>
+ <artifactId>libthrift</artifactId>
+ <version>${libthrift.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.facebook.airlift</groupId>
+ <artifactId>configuration</artifactId>
+ <version>${airlift.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.facebook.airlift</groupId>
+ <artifactId>bootstrap</artifactId>
+ <version>${airlift.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.facebook.airlift</groupId>
+ <artifactId>json</artifactId>
+ <version>${airlift.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
<dependency>
<groupId>com.facebook.presto</groupId>
<artifactId>presto-spi</artifactId>
@@ -67,13 +112,6 @@ under the License.
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>com.facebook.presto.hadoop</groupId>
- <artifactId>hadoop-apache2</artifactId>
- <version>${hadoop.apache2.version}</version>
- <scope>provided</scope>
- </dependency>
-
<dependency>
<groupId>com.facebook.presto</groupId>
<artifactId>presto-main</artifactId>
@@ -113,34 +151,4 @@ under the License.
</dependency>
</dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-shade-plugin</artifactId>
- <executions>
- <execution>
- <id>shade-paimon</id>
- <phase>package</phase>
- <goals>
- <goal>shade</goal>
- </goals>
- <configuration>
- <artifactSet>
- <includes combine.children="append">
-
<include>org.apache.paimon:paimon-bundle</include>
- <include>org.slf4j:slf4j-api</include>
-
<include>org.apache.logging.log4j:log4j-api</include>
-
<include>org.apache.logging.log4j:log4j-core</include>
-
<include>org.apache.logging.log4j:log4j-slf4j-impl</include>
-
<include>org.apache.logging.log4j:log4j-1.2-api</include>
-
<include>org.apache.commons:commons-lang3</include>
- </includes>
- </artifactSet>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
</project>
\ No newline at end of file
diff --git
a/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoMetadataFactory.java
b/paimon-presto-common/src/main/java/org/apache/paimon/presto/PaimonConfig.java
similarity index 51%
copy from
paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoMetadataFactory.java
copy to
paimon-presto-common/src/main/java/org/apache/paimon/presto/PaimonConfig.java
index 5455850..977d542 100644
---
a/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoMetadataFactory.java
+++
b/paimon-presto-common/src/main/java/org/apache/paimon/presto/PaimonConfig.java
@@ -18,23 +18,42 @@
package org.apache.paimon.presto;
-import org.apache.paimon.options.Options;
+import com.facebook.airlift.configuration.Config;
-import com.facebook.presto.common.type.TypeManager;
-import com.facebook.presto.spi.connector.ConnectorMetadata;
+/** Used for configuration item inspection and management. */
+public class PaimonConfig {
-/** Presto MetadataFactory. */
-public class PrestoMetadataFactory {
+ private String warehouse;
+ private String metastore;
+ private String uri;
- private final Options catalogOptions;
- private final TypeManager typeManager;
+ public String getWarehouse() {
+ return warehouse;
+ }
+
+ @Config("warehouse")
+ public PaimonConfig setWarehouse(String warehouse) {
+ this.warehouse = warehouse;
+ return this;
+ }
+
+ public String getMetastore() {
+ return metastore;
+ }
+
+ @Config("metastore")
+ public PaimonConfig setMetastore(String metastore) {
+ this.metastore = metastore;
+ return this;
+ }
- public PrestoMetadataFactory(Options catalogOptions, TypeManager
typeManager) {
- this.catalogOptions = catalogOptions;
- this.typeManager = typeManager;
+ public String getUri() {
+ return uri;
}
- public ConnectorMetadata create() {
- return new PrestoMetadata(catalogOptions, typeManager);
+ @Config("uri")
+ public PaimonConfig setUri(String uri) {
+ this.uri = uri;
+ return this;
}
}
diff --git
a/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoMetadataFactory.java
b/paimon-presto-common/src/main/java/org/apache/paimon/presto/PaimonConnectorId.java
similarity index 53%
rename from
paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoMetadataFactory.java
rename to
paimon-presto-common/src/main/java/org/apache/paimon/presto/PaimonConnectorId.java
index 5455850..1b94509 100644
---
a/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoMetadataFactory.java
+++
b/paimon-presto-common/src/main/java/org/apache/paimon/presto/PaimonConnectorId.java
@@ -18,23 +18,38 @@
package org.apache.paimon.presto;
-import org.apache.paimon.options.Options;
+import java.util.Objects;
-import com.facebook.presto.common.type.TypeManager;
-import com.facebook.presto.spi.connector.ConnectorMetadata;
+import static java.util.Objects.requireNonNull;
-/** Presto MetadataFactory. */
-public class PrestoMetadataFactory {
+/** Wrap for connector id. */
+public final class PaimonConnectorId {
- private final Options catalogOptions;
- private final TypeManager typeManager;
+ private final String id;
- public PrestoMetadataFactory(Options catalogOptions, TypeManager
typeManager) {
- this.catalogOptions = catalogOptions;
- this.typeManager = typeManager;
+ public PaimonConnectorId(String id) {
+ this.id = requireNonNull(id, "id is null");
}
- public ConnectorMetadata create() {
- return new PrestoMetadata(catalogOptions, typeManager);
+ @Override
+ public String toString() {
+ return id;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if ((obj == null) || (getClass() != obj.getClass())) {
+ return false;
+ }
+ PaimonConnectorId other = (PaimonConnectorId) obj;
+ return Objects.equals(this.id, other.id);
}
}
diff --git
a/paimon-presto-common/src/main/java/org/apache/paimon/presto/PaimonModule.java
b/paimon-presto-common/src/main/java/org/apache/paimon/presto/PaimonModule.java
new file mode 100644
index 0000000..5dee0a8
--- /dev/null
+++
b/paimon-presto-common/src/main/java/org/apache/paimon/presto/PaimonModule.java
@@ -0,0 +1,77 @@
+/*
+ * 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.paimon.presto;
+
+import org.apache.paimon.options.Options;
+
+import com.facebook.presto.common.type.TypeManager;
+import com.facebook.presto.spi.function.FunctionMetadataManager;
+import com.facebook.presto.spi.function.StandardFunctionResolution;
+import com.facebook.presto.spi.relation.RowExpressionService;
+import com.google.inject.Binder;
+import com.google.inject.Module;
+import com.google.inject.Scopes;
+
+import java.util.Map;
+
+import static com.facebook.airlift.configuration.ConfigBinder.configBinder;
+import static java.util.Objects.requireNonNull;
+
+/** Module for binding instance. */
+public class PaimonModule implements Module {
+
+ private final String connectorId;
+ private final TypeManager typeManager;
+ private final FunctionMetadataManager functionMetadataManager;
+ private final StandardFunctionResolution standardFunctionResolution;
+ private final RowExpressionService rowExpressionService;
+ private final Map<String, String> config;
+
+ public PaimonModule(
+ String connectorId,
+ TypeManager typeManager,
+ FunctionMetadataManager functionMetadataManager,
+ StandardFunctionResolution standardFunctionResolution,
+ RowExpressionService rowExpressionService,
+ Map<String, String> config) {
+ this.connectorId = requireNonNull(connectorId, "catalogName is null");
+ this.typeManager = requireNonNull(typeManager, "typeManager is null");
+ this.functionMetadataManager = functionMetadataManager;
+ this.standardFunctionResolution = standardFunctionResolution;
+ this.rowExpressionService = rowExpressionService;
+ this.config = config;
+ }
+
+ @Override
+ public void configure(Binder binder) {
+ binder.bind(PaimonConnectorId.class).toInstance(new
PaimonConnectorId(connectorId));
+ binder.bind(TypeManager.class).toInstance(typeManager);
+ binder.bind(PrestoConnector.class).in(Scopes.SINGLETON);
+ binder.bind(PrestoMetadata.class).in(Scopes.SINGLETON);
+ binder.bind(PrestoSplitManager.class).in(Scopes.SINGLETON);
+ binder.bind(PrestoPageSourceProvider.class).in(Scopes.SINGLETON);
+
binder.bind(FunctionMetadataManager.class).toInstance(functionMetadataManager);
+
binder.bind(StandardFunctionResolution.class).toInstance(standardFunctionResolution);
+
binder.bind(RowExpressionService.class).toInstance(rowExpressionService);
+ binder.bind(Options.class).toInstance(Options.fromMap(config));
+ binder.bind(PrestoTransactionManager.class).in(Scopes.SINGLETON);
+
+ configBinder(binder).bindConfig(PaimonConfig.class);
+ }
+}
diff --git
a/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoConnector.java
b/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoConnector.java
index 1566028..a9d64c9 100644
---
a/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoConnector.java
+++
b/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoConnector.java
@@ -23,21 +23,20 @@ import
com.facebook.presto.spi.connector.ConnectorCommitHandle;
import com.facebook.presto.spi.connector.ConnectorTransactionHandle;
import com.facebook.presto.spi.connector.EmptyConnectorCommitHandle;
+import javax.inject.Inject;
+
/** Presto {@link Connector}. */
public class PrestoConnector extends PrestoConnectorBase {
private final PrestoTransactionManager transactionManager;
+ @Inject
public PrestoConnector(
PrestoTransactionManager transactionManager,
PrestoSplitManager prestoSplitManager,
PrestoPageSourceProvider prestoPageSourceProvider,
- PrestoMetadataFactory prestoMetadataFactory) {
- super(
- transactionManager,
- prestoSplitManager,
- prestoPageSourceProvider,
- prestoMetadataFactory);
+ PrestoMetadata prestoMetadata) {
+ super(transactionManager, prestoSplitManager,
prestoPageSourceProvider, prestoMetadata);
this.transactionManager = transactionManager;
}
diff --git
a/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoConnectorBase.java
b/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoConnectorBase.java
index ceeb358..8d840a4 100644
---
a/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoConnectorBase.java
+++
b/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoConnectorBase.java
@@ -37,19 +37,18 @@ public abstract class PrestoConnectorBase implements
Connector {
private final PrestoTransactionManager transactionManager;
private final PrestoSplitManager prestoSplitManager;
private final PrestoPageSourceProvider prestoPageSourceProvider;
- private final PrestoMetadataFactory prestoMetadataFactory;
+ private final PrestoMetadata prestoMetadata;
public PrestoConnectorBase(
PrestoTransactionManager transactionManager,
PrestoSplitManager prestoSplitManager,
PrestoPageSourceProvider prestoPageSourceProvider,
- PrestoMetadataFactory prestoMetadataFactory) {
+ PrestoMetadata prestoMetadata) {
this.transactionManager = requireNonNull(transactionManager,
"transactionManager is null");
this.prestoSplitManager = requireNonNull(prestoSplitManager,
"prestoSplitManager is null");
this.prestoPageSourceProvider =
requireNonNull(prestoPageSourceProvider,
"prestoPageSourceProvider is null");
- this.prestoMetadataFactory =
- requireNonNull(prestoMetadataFactory, "prestoMetadataFactory
is null");
+ this.prestoMetadata = requireNonNull(prestoMetadata, "prestoMetadata
is null");
}
@Override
@@ -59,7 +58,7 @@ public abstract class PrestoConnectorBase implements
Connector {
ConnectorTransactionHandle transaction = new PrestoTransactionHandle();
try (ThreadContextClassLoader ignored =
new ThreadContextClassLoader(getClass().getClassLoader())) {
- transactionManager.put(transaction,
prestoMetadataFactory.create());
+ transactionManager.put(transaction, prestoMetadata);
}
return transaction;
}
diff --git
a/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoConnectorFactory.java
b/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoConnectorFactory.java
index d2f3552..8dffb5e 100644
---
a/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoConnectorFactory.java
+++
b/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoConnectorFactory.java
@@ -18,15 +18,18 @@
package org.apache.paimon.presto;
-import org.apache.paimon.options.Options;
-
+import com.facebook.airlift.bootstrap.Bootstrap;
+import com.facebook.airlift.json.JsonModule;
import com.facebook.presto.spi.ConnectorHandleResolver;
import com.facebook.presto.spi.connector.Connector;
import com.facebook.presto.spi.connector.ConnectorContext;
import com.facebook.presto.spi.connector.ConnectorFactory;
+import com.google.inject.Injector;
+import java.lang.reflect.Method;
import java.util.Map;
+import static com.google.common.base.Throwables.throwIfUnchecked;
import static java.util.Objects.requireNonNull;
/** Presto {@link ConnectorFactory}. */
@@ -46,10 +49,35 @@ public class PrestoConnectorFactory implements
ConnectorFactory {
public Connector create(
String catalogName, Map<String, String> config, ConnectorContext
context) {
requireNonNull(config, "config is null");
- return new PrestoConnector(
- new PrestoTransactionManager(),
- new PrestoSplitManager(),
- new PrestoPageSourceProvider(),
- new PrestoMetadataFactory(Options.fromMap(config),
context.getTypeManager())) {};
+
+ try {
+ Bootstrap app =
+ new Bootstrap(
+ new JsonModule(),
+ new PaimonModule(
+ catalogName,
+ context.getTypeManager(),
+ context.getFunctionMetadataManager(),
+ context.getStandardFunctionResolution(),
+ context.getRowExpressionService(),
+ config));
+
+ Bootstrap bootstrap =
+
app.doNotInitializeLogging().setRequiredConfigurationProperties(config).quiet();
+ try {
+ // Using reflection to achieve compatibility with different
versions of
+ // dependencies.
+ Method noStrictConfigMethod =
Bootstrap.class.getMethod("noStrictConfig");
+ noStrictConfigMethod.invoke(bootstrap);
+ } catch (java.lang.NoSuchMethodException e) {
+ // ignore
+ }
+ Injector injector = bootstrap.initialize();
+
+ return injector.getInstance(PrestoConnector.class);
+ } catch (Exception e) {
+ throwIfUnchecked(e);
+ throw new RuntimeException(e);
+ }
}
}
diff --git
a/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoMetadata.java
b/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoMetadata.java
index e556f35..80463b7 100644
---
a/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoMetadata.java
+++
b/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoMetadata.java
@@ -49,6 +49,8 @@ import
com.facebook.presto.spi.connector.ConnectorOutputMetadata;
import com.facebook.presto.spi.statistics.ComputedStatistics;
import io.airlift.slice.Slice;
+import javax.inject.Inject;
+
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.ArrayList;
@@ -73,6 +75,7 @@ public class PrestoMetadata implements ConnectorMetadata {
private final Catalog catalog;
private final TypeManager typeManager;
+ @Inject
public PrestoMetadata(Options catalogOptions, TypeManager typeManager) {
try {
SecurityContext.install(catalogOptions);