|
| 1 | ++++ |
| 2 | +title = "Presto" |
| 3 | +weight = 6 |
| 4 | ++++ |
| 5 | + |
| 6 | +## Background Information |
| 7 | + |
| 8 | +ShardingSphere does not provide support for `driverClassName` of `com.facebook.presto.jdbc.PrestoDriver` by default. |
| 9 | +ShardingSphere's support for Presto JDBC Driver is in an optional module. |
| 10 | + |
| 11 | +## Prerequisites |
| 12 | + |
| 13 | +To use a `jdbcUrl` like `jdbc:presto://localhost:8080/iceberg/demo_ds_0` for the data node in the ShardingSphere configuration file, |
| 14 | +Possible Maven dependencies are as follows, |
| 15 | + |
| 16 | +```xml |
| 17 | +<dependencies> |
| 18 | + <dependency> |
| 19 | + <groupId>org.apache.shardingsphere</groupId> |
| 20 | + <artifactId>shardingsphere-jdbc</artifactId> |
| 21 | + <version>${shardingsphere.version}</version> |
| 22 | + </dependency> |
| 23 | + <dependency> |
| 24 | + <groupId>org.apache.shardingsphere</groupId> |
| 25 | + <artifactId>shardingsphere-parser-sql-presto</artifactId> |
| 26 | + <version>${shardingsphere.version}</version> |
| 27 | + </dependency> |
| 28 | + <dependency> |
| 29 | + <groupId>com.facebook.presto</groupId> |
| 30 | + <artifactId>presto-jdbc</artifactId> |
| 31 | + <version>0.292</version> |
| 32 | + </dependency> |
| 33 | +</dependencies> |
| 34 | +``` |
| 35 | + |
| 36 | +## Configuration Example |
| 37 | + |
| 38 | +### Start Presto |
| 39 | + |
| 40 | +Write a Docker Compose file to start Presto. |
| 41 | +This will start a Presto node that is both a coordinator and a worker node, and configure the Iceberg Connector for the node. |
| 42 | +In addition, this Iceberg Connector will start a Hive Metastore Server using a local file system directory. |
| 43 | + |
| 44 | +```yaml |
| 45 | +services: |
| 46 | + presto: |
| 47 | + image: prestodb/presto:0.292 |
| 48 | + ports: |
| 49 | + - "8080:8080" |
| 50 | + volumes: |
| 51 | + - ./iceberg.properties:/opt/presto-server/etc/catalog/iceberg.properties |
| 52 | +``` |
| 53 | +
|
| 54 | +The same folder contains the file `iceberg.properties`, the contents are as follows, |
| 55 | + |
| 56 | +```properties |
| 57 | +connector.name=iceberg |
| 58 | +iceberg.catalog.type=hive |
| 59 | +hive.metastore=file |
| 60 | +hive.metastore.catalog.dir=file:/home/iceberg_data |
| 61 | +``` |
| 62 | + |
| 63 | +### Create business-related schemas, databases, and tables |
| 64 | + |
| 65 | +Use third-party tools to create business-related schemas, databases, and tables in Presto. |
| 66 | +Taking DBeaver Community as an example, if you use Ubuntu 24.04, you can quickly install it through Snapcraft. |
| 67 | + |
| 68 | +```shell |
| 69 | +sudo apt update && sudo apt upgrade -y |
| 70 | +sudo snap install dbeaver-ce |
| 71 | +snap run dbeaver-ce |
| 72 | +``` |
| 73 | + |
| 74 | +In DBeaver Community, use `jdbcUrl` of `jdbc:presto://localhost:8080/iceberg`, `username` of `test` to connect to Presto, and leave `password` blank. |
| 75 | +Execute the following SQL, |
| 76 | + |
| 77 | +```sql |
| 78 | +-- noinspection SqlNoDataSourceInspectionForFile |
| 79 | +CREATE SCHEMA iceberg.demo_ds_0; |
| 80 | +CREATE SCHEMA iceberg.demo_ds_1; |
| 81 | +CREATE SCHEMA iceberg.demo_ds_2; |
| 82 | +``` |
| 83 | + |
| 84 | +Use the `jdbcUrl` of `jdbc:presto://localhost:8080/iceberg/demo_ds_0`, |
| 85 | +`jdbc:presto://localhost:8080/iceberg/demo_ds_1` and `jdbc:presto://localhost:8080/iceberg/demo_ds_2` to connect to Presto and execute the following SQL, |
| 86 | + |
| 87 | +```sql |
| 88 | +-- noinspection SqlNoDataSourceInspectionForFile |
| 89 | +CREATE TABLE IF NOT EXISTS t_order ( |
| 90 | + order_id BIGINT NOT NULL, |
| 91 | + order_type INTEGER, |
| 92 | + user_id INTEGER NOT NULL, |
| 93 | + address_id BIGINT NOT NULL, |
| 94 | + status VARCHAR(50) |
| 95 | +); |
| 96 | +truncate table t_order; |
| 97 | +``` |
| 98 | + |
| 99 | +### Create ShardingSphere data source in business project |
| 100 | + |
| 101 | +After the business project introduces the dependencies involved in `Prerequisites`, |
| 102 | +write the ShardingSphere data source configuration file `demo.yaml` on the classpath of the business project. |
| 103 | + |
| 104 | +```yaml |
| 105 | +dataSources: |
| 106 | + ds_0: |
| 107 | + dataSourceClassName: com.zaxxer.hikari.HikariDataSource |
| 108 | + driverClassName: com.facebook.presto.jdbc.PrestoDriver |
| 109 | + jdbcUrl: jdbc:presto://localhost:8080/iceberg/demo_ds_0 |
| 110 | + username: test |
| 111 | + ds_1: |
| 112 | + dataSourceClassName: com.zaxxer.hikari.HikariDataSource |
| 113 | + driverClassName: com.facebook.presto.jdbc.PrestoDriver |
| 114 | + jdbcUrl: jdbc:presto://localhost:8080/iceberg/demo_ds_1 |
| 115 | + username: test |
| 116 | + ds_2: |
| 117 | + dataSourceClassName: com.zaxxer.hikari.HikariDataSource |
| 118 | + driverClassName: com.facebook.presto.jdbc.PrestoDriver |
| 119 | + jdbcUrl: jdbc:presto://localhost:8080/iceberg/demo_ds_2 |
| 120 | + username: test |
| 121 | +rules: |
| 122 | + - !SHARDING |
| 123 | + tables: |
| 124 | + t_order: |
| 125 | + actualDataNodes: <LITERAL>ds_0.t_order, ds_1.t_order, ds_2.t_order |
| 126 | + keyGenerateStrategy: |
| 127 | + column: order_id |
| 128 | + keyGeneratorName: snowflake |
| 129 | + defaultDatabaseStrategy: |
| 130 | + standard: |
| 131 | + shardingColumn: user_id |
| 132 | + shardingAlgorithmName: inline |
| 133 | + shardingAlgorithms: |
| 134 | + inline: |
| 135 | + type: INLINE |
| 136 | + props: |
| 137 | + algorithm-expression: ds_${user_id % 2} |
| 138 | + keyGenerators: |
| 139 | + snowflake: |
| 140 | + type: SNOWFLAKE |
| 141 | +``` |
| 142 | + |
| 143 | +### Enjoy integration |
| 144 | + |
| 145 | +Create a ShardingSphere data source to enjoy integration, |
| 146 | + |
| 147 | +```java |
| 148 | +import com.zaxxer.hikari.HikariConfig; |
| 149 | +import com.zaxxer.hikari.HikariDataSource; |
| 150 | +import java.sql.Connection; |
| 151 | +import java.sql.SQLException; |
| 152 | +import java.sql.Statement; |
| 153 | +public class ExampleUtils { |
| 154 | + void test() throws SQLException { |
| 155 | + HikariConfig config = new HikariConfig(); |
| 156 | + config.setJdbcUrl("jdbc:shardingsphere:classpath:demo.yaml"); |
| 157 | + config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver"); |
| 158 | + try (HikariDataSource dataSource = new HikariDataSource(config); |
| 159 | + Connection connection = dataSource.getConnection(); |
| 160 | + Statement statement = connection.createStatement()) { |
| 161 | + statement.execute("INSERT INTO t_order (user_id, order_type, address_id, status) VALUES (1, 1, 1, 'INSERT_TEST')"); |
| 162 | + statement.executeQuery("SELECT * FROM t_order"); |
| 163 | + statement.execute("DELETE FROM t_order WHERE user_id=1"); |
| 164 | + statement.execute("DROP TABLE IF EXISTS t_order"); |
| 165 | + } |
| 166 | + } |
| 167 | +} |
| 168 | +``` |
| 169 | + |
| 170 | +## Usage Limitations |
| 171 | + |
| 172 | +### SQL Limitations |
| 173 | + |
| 174 | +ShardingSphere JDBC DataSource does not yet support the execution of Presto's `create table` and `truncate table` statements. |
| 175 | + |
| 176 | +### Transaction Limitations |
| 177 | + |
| 178 | +Presto does not support local transactions, XA transactions, or Seata's AT mode transactions at the ShardingSphere integration level. |
| 179 | + |
| 180 | +There are known issues on the ShardingSphere side for Presto's local transactions at the ShardingSphere integration level. |
| 181 | + |
| 182 | +### Connector Limitations |
| 183 | + |
| 184 | +Affected by https://github.com/prestodb/presto/issues/23226 , there are known issues with the health check of the Presto Memory connector, |
| 185 | +developers should not connect to the Presto Memory connector in the ShardingSphere configuration file. |
0 commit comments