Skip to content
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

[Fix]sqlserver table path include dot bug #7648

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ protected String getListDatabaseSql() {

@Override
protected String getListTableSql(String databaseName) {
return "SELECT TABLE_SCHEMA, TABLE_NAME FROM "
+ databaseName
+ ".INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'";
return String.format(
"SELECT TABLE_SCHEMA, TABLE_NAME FROM [%s].[INFORMATION_SCHEMA].[TABLES] WHERE TABLE_TYPE = 'BASE TABLE'",
databaseName);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,15 @@ public String tableIdentifier(TablePath tablePath) {

@Override
public TablePath parse(String tablePath) {
return TablePath.of(tablePath, true);
if (!tablePath.contains("].[")) {
return TablePath.of(tablePath, true);
} else {
String[] parts = tablePath.substring(1, tablePath.length() - 1).split("\\]\\.\\[");
String databaseName = parts[0];
String schemaName = parts[1];
String tableName = parts[2];
return TablePath.of(databaseName, schemaName, tableName);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.seatunnel.api.table.catalog.TablePath;
import org.apache.seatunnel.api.table.type.SeaTunnelRow;
import org.apache.seatunnel.common.exception.SeaTunnelRuntimeException;
import org.apache.seatunnel.common.utils.ExceptionUtils;
import org.apache.seatunnel.connectors.seatunnel.jdbc.catalog.sqlserver.SqlServerCatalog;
import org.apache.seatunnel.connectors.seatunnel.jdbc.catalog.sqlserver.SqlServerURLParser;
import org.apache.seatunnel.e2e.common.TestSuiteBase;
Expand All @@ -40,6 +41,7 @@
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.sql.Statement;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
Expand All @@ -55,6 +57,7 @@ public class JdbcSqlServerIT extends AbstractJdbcIT {
private static final String SQLSERVER_IMAGE = "mcr.microsoft.com/mssql/server:2022-latest";
private static final String SQLSERVER_CONTAINER_HOST = "sqlserver";
private static final String SQLSERVER_SOURCE = "source";
private static final String SQLSERVER_SOURCE_WITH_DOT = "source.source.source.source";
private static final String SQLSERVER_SINK = "sink";
private static final String SQLSERVER_DATABASE = "master";
private static final String SQLSERVER_SCHEMA = "dbo";
Expand All @@ -67,7 +70,9 @@ public class JdbcSqlServerIT extends AbstractJdbcIT {
+ SQLSERVER_DATABASE;
private static final String DRIVER_CLASS = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
private static final List<String> CONFIG_FILE =
Lists.newArrayList("/jdbc_sqlserver_source_to_sink.conf");
Lists.newArrayList(
"/jdbc_sqlserver_source_to_sink.conf",
"/jdbc_sqlserver_source_to_sink_with_dot.conf");
private static final String CREATE_SQL =
"CREATE TABLE %s (\n"
+ "\tINT_IDENTITY_TEST int identity,\n"
Expand Down Expand Up @@ -106,6 +111,44 @@ public class JdbcSqlServerIT extends AbstractJdbcIT {
+ "\tCONSTRAINT PK_TEST_INDEX PRIMARY KEY (INT_IDENTITY_TEST)\n"
+ ");";

private static final String CREATE_SQL_WITH_DOT =
"CREATE TABLE %s (\n"
+ "\tINT_IDENTITY_TEST int identity,\n"
+ "\tBIGINT_TEST bigint NOT NULL,\n"
+ "\tBINARY_TEST binary(255) NULL,\n"
+ "\tBIT_TEST bit NULL,\n"
+ "\tCHAR_TEST char(255) COLLATE Chinese_PRC_CS_AS NULL,\n"
+ "\tDATE_TEST date NULL,\n"
+ "\tDATETIME_TEST datetime NULL,\n"
+ "\tDATETIME2_TEST datetime2 NULL,\n"
+ "\tDATETIMEOFFSET_TEST datetimeoffset NULL,\n"
+ "\tDECIMAL_TEST decimal(18,2) NULL,\n"
+ "\tFLOAT_TEST float NULL,\n"
+ "\tIMAGE_TEST image NULL,\n"
+ "\tINT_TEST int NULL,\n"
+ "\tMONEY_TEST money NULL,\n"
+ "\tNCHAR_TEST nchar(1) COLLATE Chinese_PRC_CS_AS NULL,\n"
+ "\tNTEXT_TEST ntext COLLATE Chinese_PRC_CS_AS NULL,\n"
+ "\tNUMERIC_TEST numeric(18,2) NULL,\n"
+ "\tNVARCHAR_TEST nvarchar(16) COLLATE Chinese_PRC_CS_AS NULL,\n"
+ "\tNVARCHAR_MAX_TEST nvarchar(MAX) COLLATE Chinese_PRC_CS_AS NULL,\n"
+ "\tREAL_TEST real NULL,\n"
+ "\tSMALLDATETIME_TEST smalldatetime NULL,\n"
+ "\tSMALLINT_TEST smallint NULL,\n"
+ "\tSMALLMONEY_TEST smallmoney NULL,\n"
+ "\tSQL_VARIANT_TEST sql_variant NULL,\n"
+ "\tTEXT_TEST text COLLATE Chinese_PRC_CS_AS NULL,\n"
+ "\tTIME_TEST time NULL,\n"
+ "\tTINYINT_TEST tinyint NULL,\n"
+ "\tUNIQUEIDENTIFIER_TEST uniqueidentifier NULL,\n"
+ "\tVARBINARY_TEST varbinary(255) NULL,\n"
+ "\tVARBINARY_MAX_TEST varbinary(MAX) NULL,\n"
+ "\tVARCHAR_TEST varchar(16) COLLATE Chinese_PRC_CS_AS NULL,\n"
+ "\tVARCHAR_MAX_TEST varchar(MAX) COLLATE Chinese_PRC_CS_AS DEFAULT NULL NULL,\n"
+ "\tXML_TEST xml NULL,\n"
+ "\tCONSTRAINT PK_TEST_INDEX_WITH_DOT PRIMARY KEY (INT_IDENTITY_TEST)\n"
+ ");";

private static final String SINK_CREATE_SQL =
"CREATE TABLE %s (\n"
+ "\tINT_IDENTITY_TEST int NULL,\n"
Expand Down Expand Up @@ -184,6 +227,48 @@ JdbcCase getJdbcCase() {
.build();
}

@Override
protected void createNeededTables() {
try (Statement statement = connection.createStatement()) {
String createTemplate = jdbcCase.getCreateSql();

String createSource =
String.format(
createTemplate,
buildTableInfoWithSchema(
jdbcCase.getDatabase(),
jdbcCase.getSchema(),
jdbcCase.getSourceTable()));

String createSourceWithDot =
String.format(
CREATE_SQL_WITH_DOT,
buildTableInfoWithSchema(
jdbcCase.getDatabase(),
jdbcCase.getSchema(),
SQLSERVER_SOURCE_WITH_DOT));
if (jdbcCase.getSinkCreateSql() != null) {
createTemplate = jdbcCase.getSinkCreateSql();
}
String createSink =
String.format(
createTemplate,
buildTableInfoWithSchema(
jdbcCase.getDatabase(),
jdbcCase.getSchema(),
jdbcCase.getSinkTable()));

statement.execute(createSource);
statement.execute(createSourceWithDot);
statement.execute(createSink);

connection.commit();
} catch (Exception exception) {
log.error(ExceptionUtils.getMessage(exception));
throw new SeaTunnelRuntimeException(JdbcITErrorCode.CREATE_TABLE_FAILED, exception);
}
}

@Override
void compareResult(String executeKey) throws SQLException, IOException {}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# 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.
#
######
###### This config file is a demonstration of streaming processing in seatunnel config
######

env {
parallelism = 1
job.mode = "BATCH"
}

source {
# This is a example source plugin **only for test and demonstrate the feature source plugin**
Jdbc {
driver = com.microsoft.sqlserver.jdbc.SQLServerDriver
url = "jdbc:sqlserver://sqlserver;encrypt=false;"
user = SA
password = "A_Str0ng_Required_Password"
table_path = "[master].[dbo].[source.source.source.source]"
}

# If you would like to get more information about how to configure seatunnel and see full list of source plugins,
# please go to https://seatunnel.apache.org/docs/connector-v2/source/Jdbc
}

transform {

# If you would like to get more information about how to configure seatunnel and see full list of transform plugins,
# please go to https://seatunnel.apache.org/docs/transform-v2/sql
}

sink {
console {
}
}
Loading