View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.shardingsphere.data.pipeline.core.sqlbuilder.dialect;
19  
20  import org.apache.shardingsphere.data.pipeline.core.ingest.record.DataRecord;
21  import org.apache.shardingsphere.database.connector.core.spi.DatabaseTypedSPI;
22  import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI;
23  
24  import javax.sql.DataSource;
25  import java.sql.SQLException;
26  import java.util.Collection;
27  import java.util.Optional;
28  
29  /**
30   * Dialect pipeline SQL builder.
31   */
32  @SingletonSPI
33  public interface DialectPipelineSQLBuilder extends DatabaseTypedSPI {
34      
35      /**
36       * Build create schema SQL.
37       *
38       * @param schemaName schema name
39       * @return built SQL
40       */
41      default Optional<String> buildCreateSchemaSQL(final String schemaName) {
42          return Optional.empty();
43      }
44      
45      /**
46       * Build on duplicate clause of insert SQL.
47       *
48       * @param dataRecord data record
49       * @return built SQL clause
50       */
51      default Optional<String> buildInsertOnDuplicateClause(final DataRecord dataRecord) {
52          return Optional.empty();
53      }
54      
55      /**
56       * Build check empty table SQL.
57       *
58       * @param qualifiedTableName qualified table name
59       * @return built SQL
60       */
61      String buildCheckEmptyTableSQL(String qualifiedTableName);
62      
63      /**
64       * Build estimated count SQL.
65       *
66       * @param catalogName catalog name
67       * @param qualifiedTableName qualified table name
68       * @return built SQL
69       */
70      default Optional<String> buildEstimatedCountSQL(final String catalogName, final String qualifiedTableName) {
71          return Optional.empty();
72      }
73      
74      /**
75       * Build CRC32 SQL.
76       *
77       * @param qualifiedTableName qualified table name
78       * @param columnName column name
79       * @return built SQL
80       */
81      default Optional<String> buildCRC32SQL(final String qualifiedTableName, final String columnName) {
82          return Optional.empty();
83      }
84      
85      /**
86       * Build split by unique key subquery clause.
87       *
88       * @param qualifiedTableName qualified table name
89       * @param uniqueKey unique key
90       * @param hasLowerBound has lower bound
91       * @return built SQL
92       */
93      String buildSplitByUniqueKeyRangedSubqueryClause(String qualifiedTableName, String uniqueKey, boolean hasLowerBound);
94      
95      /**
96       * Build create table SQLs.
97       *
98       * @param dataSource dataSource
99       * @param schemaName schema name
100      * @param tableName table name
101      * @return built SQLs
102      * @throws SQLException SQL exception
103      */
104     Collection<String> buildCreateTableSQLs(DataSource dataSource, String schemaName, String tableName) throws SQLException;
105     
106     /**
107      * Build query current position SQL.
108      *
109      * @return built SQL
110      */
111     default Optional<String> buildQueryCurrentPositionSQL() {
112         return Optional.empty();
113     }
114     
115     /**
116      * Wrap with page query.
117      *
118      * @param sql SQL
119      * @return wrapped SQL
120      */
121     String wrapWithPageQuery(String sql);
122 }