-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Core] Support jdbc catalog #2866
Changes from 1 commit
5c1fa42
6a70411
3df2995
8c2e10d
0b7b739
bd81c01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ Paimon catalogs currently support two types of metastores: | |
|
||
* `filesystem` metastore (default), which stores both metadata and table files in filesystems. | ||
* `hive` metastore, which additionally stores metadata in Hive metastore. Users can directly access the tables from Hive. | ||
* `jdbc` metastore, which additionally stores metadata in relational databases such as MySQL, Postgres, etc. | ||
|
||
See [CatalogOptions]({{< ref "maintenance/configurations#catalogoptions" >}}) for detailed options when creating a catalog. | ||
|
||
|
@@ -175,3 +176,185 @@ Using the table option facilitates the convenient definition of Hive table param | |
Parameters prefixed with `hive.` will be automatically defined in the `TBLPROPERTIES` of the Hive table. | ||
For instance, using the option `hive.table.owner=Jon` will automatically add the parameter `table.owner=Jon` to the table properties during the creation process. | ||
|
||
|
||
|
||
## Creating a Catalog with Filesystem Metastore | ||
|
||
{{< tabs "filesystem-metastore-example" >}} | ||
|
||
{{< tab "Flink" >}} | ||
|
||
The following Flink SQL registers and uses a Paimon catalog named `my_catalog`. Metadata and table files are stored under `hdfs:///path/to/warehouse`. | ||
|
||
```sql | ||
CREATE CATALOG my_catalog WITH ( | ||
'type' = 'paimon', | ||
'warehouse' = 'hdfs:///path/to/warehouse' | ||
); | ||
|
||
USE CATALOG my_catalog; | ||
``` | ||
|
||
You can define any default table options with the prefix `table-default.` for tables created in the catalog. | ||
|
||
{{< /tab >}} | ||
|
||
{{< tab "Spark3" >}} | ||
|
||
The following shell command registers a paimon catalog named `paimon`. Metadata and table files are stored under `hdfs:///path/to/warehouse`. | ||
|
||
```bash | ||
spark-sql ... \ | ||
--conf spark.sql.catalog.paimon=org.apache.paimon.spark.SparkCatalog \ | ||
--conf spark.sql.catalog.paimon.warehouse=hdfs:///path/to/warehouse | ||
``` | ||
|
||
You can define any default table options with the prefix `spark.sql.catalog.paimon.table-default.` for tables created in the catalog. | ||
|
||
After `spark-sql` is started, you can switch to the `default` database of the `paimon` catalog with the following SQL. | ||
|
||
```sql | ||
USE paimon.default; | ||
``` | ||
|
||
{{< /tab >}} | ||
|
||
{{< /tabs >}} | ||
|
||
## Creating a Catalog with Hive Metastore | ||
|
||
By using Paimon Hive catalog, changes to the catalog will directly affect the corresponding Hive metastore. Tables created in such catalog can also be accessed directly from Hive. | ||
|
||
To use Hive catalog, Database name, Table name and Field names should be **lower** case. | ||
|
||
{{< tabs "hive-metastore-example" >}} | ||
|
||
{{< tab "Flink" >}} | ||
|
||
Paimon Hive catalog in Flink relies on Flink Hive connector bundled jar. You should first download Hive connector bundled jar and add it to classpath. | ||
|
||
| Metastore version | Bundle Name | SQL Client JAR | | ||
|:------------------|:--------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| 2.3.0 - 3.1.3 | Flink Bundle | [Download](https://nightlies.apache.org/flink/flink-docs-stable/docs/connectors/table/hive/overview/#using-bundled-hive-jar) | | ||
| 1.2.0 - x.x.x | Presto Bundle | [Download](https://repo.maven.apache.org/maven2/com/facebook/presto/hive/hive-apache/1.2.2-2/hive-apache-1.2.2-2.jar) | | ||
|
||
The following Flink SQL registers and uses a Paimon Hive catalog named `my_hive`. Metadata and table files are stored under `hdfs:///path/to/warehouse`. In addition, metadata is also stored in Hive metastore. | ||
|
||
If your Hive requires security authentication such as Kerberos, LDAP, Ranger or you want the paimon table to be managed | ||
by Apache Atlas(Setting 'hive.metastore.event.listeners' in hive-site.xml). You can specify the hive-conf-dir and | ||
hadoop-conf-dir parameter to the hive-site.xml file path. | ||
|
||
```sql | ||
CREATE CATALOG my_hive WITH ( | ||
'type' = 'paimon', | ||
'metastore' = 'hive', | ||
-- 'uri' = 'thrift://<hive-metastore-host-name>:<port>', default use 'hive.metastore.uris' in HiveConf | ||
-- 'hive-conf-dir' = '...', this is recommended in the kerberos environment | ||
-- 'hadoop-conf-dir' = '...', this is recommended in the kerberos environment | ||
-- 'warehouse' = 'hdfs:///path/to/warehouse', default use 'hive.metastore.warehouse.dir' in HiveConf | ||
); | ||
|
||
USE CATALOG my_hive; | ||
``` | ||
|
||
You can define any default table options with the prefix `table-default.` for tables created in the catalog. | ||
|
||
Also, you can create [FlinkGenericCatalog]({{< ref "engines/flink" >}}). | ||
|
||
{{< /tab >}} | ||
|
||
{{< tab "Spark3" >}} | ||
|
||
Your Spark installation should be able to detect, or already contains Hive dependencies. See [here](https://spark.apache.org/docs/latest/sql-data-sources-hive-tables.html) for more information. | ||
|
||
The following shell command registers a Paimon Hive catalog named `paimon`. Metadata and table files are stored under `hdfs:///path/to/warehouse`. In addition, metadata is also stored in Hive metastore. | ||
|
||
```bash | ||
spark-sql ... \ | ||
--conf spark.sql.catalog.paimon=org.apache.paimon.spark.SparkCatalog \ | ||
--conf spark.sql.catalog.paimon.warehouse=hdfs:///path/to/warehouse \ | ||
--conf spark.sql.catalog.paimon.metastore=hive \ | ||
--conf spark.sql.catalog.paimon.uri=thrift://<hive-metastore-host-name>:<port> | ||
``` | ||
|
||
You can define any default table options with the prefix `spark.sql.catalog.paimon.table-default.` for tables created in the catalog. | ||
|
||
After `spark-sql` is started, you can switch to the `default` database of the `paimon` catalog with the following SQL. | ||
|
||
```sql | ||
USE paimon.default; | ||
``` | ||
|
||
Also, you can create [SparkGenericCatalog]({{< ref "engines/spark" >}}). | ||
|
||
{{< /tab >}} | ||
|
||
{{< /tabs >}} | ||
|
||
> When using hive catalog to change incompatible column types through alter table, you need to configure `hive.metastore.disallow.incompatible.col.type.changes=false`. see [HIVE-17832](https://issues.apache.org/jira/browse/HIVE-17832). | ||
|
||
> If you are using Hive3, please disable Hive ACID: | ||
> | ||
> ```shell | ||
> hive.strict.managed.tables=false | ||
> hive.create.as.insert.only=false | ||
> metastore.create.as.acid=false | ||
> ``` | ||
|
||
### Setting Location in Properties | ||
|
||
If you are using an object storage , and you don't want that the location of paimon table/database is accessed by the filesystem of hive, | ||
which may lead to the error such as "No FileSystem for scheme: s3a". | ||
You can set location in the properties of table/database by the config of `location-in-properties`. See | ||
[setting the location of table/database in properties ]({{< ref "maintenance/configurations#HiveCatalogOptions" >}}) | ||
|
||
### Synchronizing Partitions into Hive Metastore | ||
|
||
By default, Paimon does not synchronize newly created partitions into Hive metastore. Users will see an unpartitioned table in Hive. Partition push-down will be carried out by filter push-down instead. | ||
|
||
If you want to see a partitioned table in Hive and also synchronize newly created partitions into Hive metastore, please set the table property `metastore.partitioned-table` to true. Also see [CoreOptions]({{< ref "maintenance/configurations#CoreOptions" >}}). | ||
|
||
### Adding Parameters to a Hive Table | ||
|
||
Using the table option facilitates the convenient definition of Hive table parameters. | ||
Parameters prefixed with `hive.` will be automatically defined in the `TBLPROPERTIES` of the Hive table. | ||
For instance, using the option `hive.table.owner=Jon` will automatically add the parameter `table.owner=Jon` to the table properties during the creation process. | ||
|
||
|
||
## Creating a Catalog with JDBC Metastore | ||
|
||
By using the Paimon JDBC catalog, changes to the catalog will be directly stored in relational databases such as MySQL, postgres, etc. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
it's just that locking is not supported There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you document this? only SQLITE and MYSQL supports catalog lock |
||
|
||
{{< tabs "jdbc-metastore-example" >}} | ||
|
||
{{< tab "Flink" >}} | ||
|
||
Paimon JDBC Catalog in Flink needs to correctly add the corresponding jar package for connecting to the database. You should first download JDBC connector bundled jar and add it to classpath. such as MySQL, postgres | ||
|
||
| database type | Bundle Name | SQL Client JAR | | ||
|:--------------|:---------------------|:---------------------------------------------------------------------------| | ||
| mysql | mysql-connector-java | [Download](https://mvnrepository.com/artifact/mysql/mysql-connector-java) | | ||
| postgres | postgresql | [Download](https://mvnrepository.com/artifact/org.postgresql/postgresql) | | ||
|
||
```sql | ||
CREATE CATALOG my_jdbc WITH ( | ||
'type' = 'paimon', | ||
'metastore' = 'jdbc', | ||
-- 'uri' = 'jdbc:mysql://<host>:<port>/<databaseName>', | ||
-- 'jdbc.user' = '...', | ||
-- 'jdbc.password' = '...', | ||
-- 'initialize-catalog-tables'='true' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this one? What is the scene? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@JingsongLi When creating a JdbcCatalog, it will be determined based on this parameter whether to automatically create a table or not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When does it not need to be initialized? You added a public API. Please explain why, how to use. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or you can remove this option. |
||
-- 'warehouse' = 'hdfs:///path/to/warehouse', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warehouse should be required. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should remove |
||
); | ||
|
||
USE CATALOG my_jdbc; | ||
``` | ||
You can define any connection parameters for a database with the prefix "jdbc.". | ||
|
||
You can define any default table options with the prefix `table-default.` for tables created in the catalog. | ||
|
||
Also, you can create [FlinkGenericCatalog]({{< ref "engines/flink" >}}). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, |
||
|
||
{{< /tab >}} | ||
|
||
{{< /tabs >}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{{/* | ||
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. | ||
*/}} | ||
<table class="configuration table table-bordered"> | ||
<thead> | ||
<tr> | ||
<th class="text-left" style="width: 20%">Key</th> | ||
<th class="text-left" style="width: 15%">Default</th> | ||
<th class="text-left" style="width: 10%">Type</th> | ||
<th class="text-left" style="width: 55%">Description</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td><h5>initialize-catalog-tables</h5></td> | ||
<td style="word-wrap: break-word;">false</td> | ||
<td>Boolean</td> | ||
<td>Enable automatic table creation.</td> | ||
</tr> | ||
</tbody> | ||
</table> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* 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; | ||
|
||
/** Define client connection pool. */ | ||
public interface ClientPool<C, E extends Exception> { | ||
/** Action interface for client. */ | ||
interface Action<R, C, E extends Exception> { | ||
R run(C client) throws E; | ||
} | ||
|
||
<R> R run(Action<R, C, E> action) throws E, InterruptedException; | ||
|
||
<R> R run(Action<R, C, E> action, boolean retry) throws E, InterruptedException; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why copy this?