You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2022/05/16 12:13:11 UTC

[GitHub] [rocketmq-connect] sunxiaojian opened a new pull request, #139: Upgrade rocketmq connect jdbc

sunxiaojian opened a new pull request, #139:
URL: https://github.com/apache/rocketmq-connect/pull/139

   ## What is the purpose of the change
   
   XXXXX
   
   ## Brief changelog
   
   XX
   
   ## Verifying this change
   
   XXXX
   
   Follow this checklist to help us incorporate your contribution quickly and easily. Notice, `it would be helpful if you could finish the following 5 checklist(the last one is not necessary)before request the community to review your PR`.
   
   - [x] Make sure there is a [Github issue](https://github.com/apache/rocketmq-connect/issues) filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue. 
   - [x] Format the pull request title like `[ISSUE #123] Fix UnknownException when host config not exist`. Each commit in the pull request should have a meaningful subject line and body.
   - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
   - [x] Write necessary unit-test(over 80% coverage) to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in [test module](https://github.com/apache/rocketmq/tree/master/test).
   - [x] Run `mvn -B clean apache-rat:check findbugs:findbugs checkstyle:checkstyle` to make sure basic checks pass. Run `mvn clean install -DskipITs` to make sure unit-test pass. Run `mvn clean test-compile failsafe:integration-test`  to make sure integration-test pass.
   - [ ] If this contribution is large, please file an [Apache Individual Contributor License Agreement](http://www.apache.org/licenses/#clas).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq-connect] sunxiaojian commented on a diff in pull request #139: Upgrade rocketmq connect jdbc

Posted by GitBox <gi...@apache.org>.
sunxiaojian commented on code in PR #139:
URL: https://github.com/apache/rocketmq-connect/pull/139#discussion_r874468956


##########
connectors/rocketmq-connect-jdbc/src/main/java/org/apache/rocketmq/connect/jdbc/dialect/impl/OracleDatabaseDialect.java:
##########
@@ -0,0 +1,308 @@
+/*
+ * Copyright 2018 Confluent Inc.

Review Comment:
   > error license
   
   Oracle dialect has been deleted. Submit after the test is completed



##########
connectors/rocketmq-connect-jdbc/src/main/java/org/apache/rocketmq/connect/jdbc/dialect/impl/OracleDatabaseDialect.java:
##########
@@ -0,0 +1,308 @@
+/*
+ * Copyright 2018 Confluent Inc.
+ *
+ * Licensed under the Confluent Community License (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.confluent.io/confluent-community-license
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OF ANY KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package org.apache.rocketmq.connect.jdbc.dialect.impl;
+
+import io.openmessaging.connector.api.data.FieldType;
+import io.openmessaging.connector.api.data.Schema;
+import io.openmessaging.connector.api.errors.ConnectException;
+import org.apache.rocketmq.connect.jdbc.config.AbstractConfig;
+import org.apache.rocketmq.connect.jdbc.connector.JdbcSinkConfig;
+import org.apache.rocketmq.connect.jdbc.dialect.DatabaseDialect;
+import org.apache.rocketmq.connect.jdbc.dialect.DropOptions;
+import org.apache.rocketmq.connect.jdbc.dialect.PreparedStatementBinder;
+import org.apache.rocketmq.connect.jdbc.dialect.provider.DatabaseDialectProvider;
+import org.apache.rocketmq.connect.jdbc.schema.column.ColumnDefinition;
+import org.apache.rocketmq.connect.jdbc.schema.column.ColumnId;
+import org.apache.rocketmq.connect.jdbc.schema.table.TableDefinition;
+import org.apache.rocketmq.connect.jdbc.schema.table.TableId;
+import org.apache.rocketmq.connect.jdbc.sink.metadata.FieldsMetadata;
+import org.apache.rocketmq.connect.jdbc.sink.metadata.SchemaPair;
+import org.apache.rocketmq.connect.jdbc.sink.metadata.SinkRecordField;
+import org.apache.rocketmq.connect.jdbc.util.ExpressionBuilder;
+import org.apache.rocketmq.connect.jdbc.util.IdentifierRules;
+
+import java.io.ByteArrayInputStream;
+import java.io.StringReader;
+import java.nio.ByteBuffer;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * A  DatabaseDialect for Oracle.
+ */
+public class OracleDatabaseDialect extends GenericDatabaseDialect {
+
+  /**
+   * The provider for {@link OracleDatabaseDialect}.
+   */
+  public static class Provider extends DatabaseDialectProvider {
+    public Provider() {
+      super(OracleDatabaseDialect.class.getSimpleName(), "oracle");
+    }
+
+    @Override
+    public DatabaseDialect create(AbstractConfig config) {
+      return new OracleDatabaseDialect(config);
+    }
+  }
+
+  /**
+   * Create a new dialect instance with the given connector configuration.
+   *
+   * @param config the connector configuration; may not be null
+   */
+  public OracleDatabaseDialect(AbstractConfig config) {
+    super(config, new IdentifierRules(".", "\"", "\""));
+  }
+
+  @Override
+  protected String currentTimestampDatabaseQuery() {
+    return "select CURRENT_TIMESTAMP from dual";
+  }
+
+  @Override
+  protected String checkConnectionQuery() {
+    return "SELECT 1 FROM DUAL";
+  }
+
+  @Override
+  public StatementBinder statementBinder(
+      PreparedStatement statement,
+      JdbcSinkConfig.PrimaryKeyMode pkMode,
+      SchemaPair schemaPair,
+      FieldsMetadata fieldsMetadata,
+      TableDefinition tableDefinition,
+      JdbcSinkConfig.InsertMode insertMode
+  ) {
+    return new PreparedStatementBinder(
+        this,
+        statement,
+        pkMode,
+        schemaPair,
+        fieldsMetadata,
+        tableDefinition,
+        insertMode
+    );
+  }
+
+  @Override
+  public void bindField(
+      PreparedStatement statement,
+      int index,
+      Schema schema,
+      Object value,
+      ColumnDefinition colDef
+  ) throws SQLException {
+    if (value == null) {
+      statement.setObject(index, null);
+    } else {
+      boolean bound = maybeBindLogical(statement, index, schema, value, colDef);
+      if (!bound) {
+        bound = maybeBindPrimitive(statement, index, schema, value, colDef);
+      }
+      if (!bound) {
+        throw new ConnectException("Unsupported source data type: " + schema.getFieldType());
+      }
+    }
+  }
+
+  protected boolean maybeBindPrimitive(
+      PreparedStatement statement,
+      int index,
+      Schema schema,
+      Object value,
+      ColumnDefinition colDef
+  ) throws SQLException {
+    if (colDef == null) {
+      return super.maybeBindPrimitive(statement, index, schema, value);
+    }
+
+    if (schema.getFieldType() == FieldType.STRING) {
+      if (colDef.type() == Types.CLOB) {
+        statement.setCharacterStream(index, new StringReader((String) value));
+        return true;
+      } else if (colDef.type() == Types.NCLOB) {
+        statement.setNCharacterStream(index, new StringReader((String) value));
+        return true;
+      } else if (colDef.type() == Types.NVARCHAR || colDef.type() == Types.NCHAR) {
+        statement.setNString(index, (String) value);
+        return true;
+      } else {
+        return super.maybeBindPrimitive(statement, index, schema, value);
+      }
+    }
+
+    if (schema.getFieldType() == FieldType.BYTES && colDef.type() == Types.BLOB) {
+      if (value instanceof ByteBuffer) {
+        statement.setBlob(index, new ByteArrayInputStream(((ByteBuffer) value).array()));
+      } else if (value instanceof byte[]) {
+        statement.setBlob(index, new ByteArrayInputStream((byte[]) value));
+      } else {
+        return super.maybeBindPrimitive(statement, index, schema, value);
+      }
+      return true;
+    }
+    return super.maybeBindPrimitive(statement, index, schema, value);
+  }
+
+  @SuppressWarnings("checkstyle:CyclomaticComplexity")
+  @Override
+  protected String getSqlType(SinkRecordField field) {
+    if (field.schemaName() != null) {

Review Comment:
   > useless code
   Oracle dialect has been deleted. Submit after the test is completed
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq-connect] odbozhou merged pull request #139: Upgrade rocketmq connect jdbc

Posted by GitBox <gi...@apache.org>.
odbozhou merged PR #139:
URL: https://github.com/apache/rocketmq-connect/pull/139


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq-connect] odbozhou commented on a diff in pull request #139: Upgrade rocketmq connect jdbc

Posted by GitBox <gi...@apache.org>.
odbozhou commented on code in PR #139:
URL: https://github.com/apache/rocketmq-connect/pull/139#discussion_r874389828


##########
connectors/rocketmq-connect-jdbc/src/main/java/org/apache/rocketmq/connect/jdbc/dialect/impl/OracleDatabaseDialect.java:
##########
@@ -0,0 +1,308 @@
+/*
+ * Copyright 2018 Confluent Inc.
+ *
+ * Licensed under the Confluent Community License (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.confluent.io/confluent-community-license
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OF ANY KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package org.apache.rocketmq.connect.jdbc.dialect.impl;
+
+import io.openmessaging.connector.api.data.FieldType;
+import io.openmessaging.connector.api.data.Schema;
+import io.openmessaging.connector.api.errors.ConnectException;
+import org.apache.rocketmq.connect.jdbc.config.AbstractConfig;
+import org.apache.rocketmq.connect.jdbc.connector.JdbcSinkConfig;
+import org.apache.rocketmq.connect.jdbc.dialect.DatabaseDialect;
+import org.apache.rocketmq.connect.jdbc.dialect.DropOptions;
+import org.apache.rocketmq.connect.jdbc.dialect.PreparedStatementBinder;
+import org.apache.rocketmq.connect.jdbc.dialect.provider.DatabaseDialectProvider;
+import org.apache.rocketmq.connect.jdbc.schema.column.ColumnDefinition;
+import org.apache.rocketmq.connect.jdbc.schema.column.ColumnId;
+import org.apache.rocketmq.connect.jdbc.schema.table.TableDefinition;
+import org.apache.rocketmq.connect.jdbc.schema.table.TableId;
+import org.apache.rocketmq.connect.jdbc.sink.metadata.FieldsMetadata;
+import org.apache.rocketmq.connect.jdbc.sink.metadata.SchemaPair;
+import org.apache.rocketmq.connect.jdbc.sink.metadata.SinkRecordField;
+import org.apache.rocketmq.connect.jdbc.util.ExpressionBuilder;
+import org.apache.rocketmq.connect.jdbc.util.IdentifierRules;
+
+import java.io.ByteArrayInputStream;
+import java.io.StringReader;
+import java.nio.ByteBuffer;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * A  DatabaseDialect for Oracle.
+ */
+public class OracleDatabaseDialect extends GenericDatabaseDialect {
+
+  /**
+   * The provider for {@link OracleDatabaseDialect}.
+   */
+  public static class Provider extends DatabaseDialectProvider {
+    public Provider() {
+      super(OracleDatabaseDialect.class.getSimpleName(), "oracle");
+    }
+
+    @Override
+    public DatabaseDialect create(AbstractConfig config) {
+      return new OracleDatabaseDialect(config);
+    }
+  }
+
+  /**
+   * Create a new dialect instance with the given connector configuration.
+   *
+   * @param config the connector configuration; may not be null
+   */
+  public OracleDatabaseDialect(AbstractConfig config) {
+    super(config, new IdentifierRules(".", "\"", "\""));
+  }
+
+  @Override
+  protected String currentTimestampDatabaseQuery() {
+    return "select CURRENT_TIMESTAMP from dual";
+  }
+
+  @Override
+  protected String checkConnectionQuery() {
+    return "SELECT 1 FROM DUAL";
+  }
+
+  @Override
+  public StatementBinder statementBinder(
+      PreparedStatement statement,
+      JdbcSinkConfig.PrimaryKeyMode pkMode,
+      SchemaPair schemaPair,
+      FieldsMetadata fieldsMetadata,
+      TableDefinition tableDefinition,
+      JdbcSinkConfig.InsertMode insertMode
+  ) {
+    return new PreparedStatementBinder(
+        this,
+        statement,
+        pkMode,
+        schemaPair,
+        fieldsMetadata,
+        tableDefinition,
+        insertMode
+    );
+  }
+
+  @Override
+  public void bindField(
+      PreparedStatement statement,
+      int index,
+      Schema schema,
+      Object value,
+      ColumnDefinition colDef
+  ) throws SQLException {
+    if (value == null) {
+      statement.setObject(index, null);
+    } else {
+      boolean bound = maybeBindLogical(statement, index, schema, value, colDef);
+      if (!bound) {
+        bound = maybeBindPrimitive(statement, index, schema, value, colDef);
+      }
+      if (!bound) {
+        throw new ConnectException("Unsupported source data type: " + schema.getFieldType());
+      }
+    }
+  }
+
+  protected boolean maybeBindPrimitive(
+      PreparedStatement statement,
+      int index,
+      Schema schema,
+      Object value,
+      ColumnDefinition colDef
+  ) throws SQLException {
+    if (colDef == null) {
+      return super.maybeBindPrimitive(statement, index, schema, value);
+    }
+
+    if (schema.getFieldType() == FieldType.STRING) {
+      if (colDef.type() == Types.CLOB) {
+        statement.setCharacterStream(index, new StringReader((String) value));
+        return true;
+      } else if (colDef.type() == Types.NCLOB) {
+        statement.setNCharacterStream(index, new StringReader((String) value));
+        return true;
+      } else if (colDef.type() == Types.NVARCHAR || colDef.type() == Types.NCHAR) {
+        statement.setNString(index, (String) value);
+        return true;
+      } else {
+        return super.maybeBindPrimitive(statement, index, schema, value);
+      }
+    }
+
+    if (schema.getFieldType() == FieldType.BYTES && colDef.type() == Types.BLOB) {
+      if (value instanceof ByteBuffer) {
+        statement.setBlob(index, new ByteArrayInputStream(((ByteBuffer) value).array()));
+      } else if (value instanceof byte[]) {
+        statement.setBlob(index, new ByteArrayInputStream((byte[]) value));
+      } else {
+        return super.maybeBindPrimitive(statement, index, schema, value);
+      }
+      return true;
+    }
+    return super.maybeBindPrimitive(statement, index, schema, value);
+  }
+
+  @SuppressWarnings("checkstyle:CyclomaticComplexity")
+  @Override
+  protected String getSqlType(SinkRecordField field) {
+    if (field.schemaName() != null) {

Review Comment:
   useless code?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq-connect] odbozhou commented on a diff in pull request #139: Upgrade rocketmq connect jdbc

Posted by GitBox <gi...@apache.org>.
odbozhou commented on code in PR #139:
URL: https://github.com/apache/rocketmq-connect/pull/139#discussion_r874389829


##########
connectors/rocketmq-connect-jdbc/src/main/java/org/apache/rocketmq/connect/jdbc/dialect/impl/OracleDatabaseDialect.java:
##########
@@ -0,0 +1,308 @@
+/*
+ * Copyright 2018 Confluent Inc.
+ *
+ * Licensed under the Confluent Community License (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.confluent.io/confluent-community-license
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OF ANY KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package org.apache.rocketmq.connect.jdbc.dialect.impl;
+
+import io.openmessaging.connector.api.data.FieldType;
+import io.openmessaging.connector.api.data.Schema;
+import io.openmessaging.connector.api.errors.ConnectException;
+import org.apache.rocketmq.connect.jdbc.config.AbstractConfig;
+import org.apache.rocketmq.connect.jdbc.connector.JdbcSinkConfig;
+import org.apache.rocketmq.connect.jdbc.dialect.DatabaseDialect;
+import org.apache.rocketmq.connect.jdbc.dialect.DropOptions;
+import org.apache.rocketmq.connect.jdbc.dialect.PreparedStatementBinder;
+import org.apache.rocketmq.connect.jdbc.dialect.provider.DatabaseDialectProvider;
+import org.apache.rocketmq.connect.jdbc.schema.column.ColumnDefinition;
+import org.apache.rocketmq.connect.jdbc.schema.column.ColumnId;
+import org.apache.rocketmq.connect.jdbc.schema.table.TableDefinition;
+import org.apache.rocketmq.connect.jdbc.schema.table.TableId;
+import org.apache.rocketmq.connect.jdbc.sink.metadata.FieldsMetadata;
+import org.apache.rocketmq.connect.jdbc.sink.metadata.SchemaPair;
+import org.apache.rocketmq.connect.jdbc.sink.metadata.SinkRecordField;
+import org.apache.rocketmq.connect.jdbc.util.ExpressionBuilder;
+import org.apache.rocketmq.connect.jdbc.util.IdentifierRules;
+
+import java.io.ByteArrayInputStream;
+import java.io.StringReader;
+import java.nio.ByteBuffer;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * A  DatabaseDialect for Oracle.
+ */
+public class OracleDatabaseDialect extends GenericDatabaseDialect {
+
+  /**
+   * The provider for {@link OracleDatabaseDialect}.
+   */
+  public static class Provider extends DatabaseDialectProvider {
+    public Provider() {
+      super(OracleDatabaseDialect.class.getSimpleName(), "oracle");
+    }
+
+    @Override
+    public DatabaseDialect create(AbstractConfig config) {
+      return new OracleDatabaseDialect(config);
+    }
+  }
+
+  /**
+   * Create a new dialect instance with the given connector configuration.
+   *
+   * @param config the connector configuration; may not be null
+   */
+  public OracleDatabaseDialect(AbstractConfig config) {
+    super(config, new IdentifierRules(".", "\"", "\""));
+  }
+
+  @Override
+  protected String currentTimestampDatabaseQuery() {
+    return "select CURRENT_TIMESTAMP from dual";
+  }
+
+  @Override
+  protected String checkConnectionQuery() {
+    return "SELECT 1 FROM DUAL";
+  }
+
+  @Override
+  public StatementBinder statementBinder(
+      PreparedStatement statement,
+      JdbcSinkConfig.PrimaryKeyMode pkMode,
+      SchemaPair schemaPair,
+      FieldsMetadata fieldsMetadata,
+      TableDefinition tableDefinition,
+      JdbcSinkConfig.InsertMode insertMode
+  ) {
+    return new PreparedStatementBinder(
+        this,
+        statement,
+        pkMode,
+        schemaPair,
+        fieldsMetadata,
+        tableDefinition,
+        insertMode
+    );
+  }
+
+  @Override
+  public void bindField(
+      PreparedStatement statement,
+      int index,
+      Schema schema,
+      Object value,
+      ColumnDefinition colDef
+  ) throws SQLException {
+    if (value == null) {
+      statement.setObject(index, null);
+    } else {
+      boolean bound = maybeBindLogical(statement, index, schema, value, colDef);
+      if (!bound) {
+        bound = maybeBindPrimitive(statement, index, schema, value, colDef);
+      }
+      if (!bound) {
+        throw new ConnectException("Unsupported source data type: " + schema.getFieldType());
+      }
+    }
+  }
+
+  protected boolean maybeBindPrimitive(
+      PreparedStatement statement,
+      int index,
+      Schema schema,
+      Object value,
+      ColumnDefinition colDef
+  ) throws SQLException {
+    if (colDef == null) {
+      return super.maybeBindPrimitive(statement, index, schema, value);
+    }
+
+    if (schema.getFieldType() == FieldType.STRING) {
+      if (colDef.type() == Types.CLOB) {
+        statement.setCharacterStream(index, new StringReader((String) value));
+        return true;
+      } else if (colDef.type() == Types.NCLOB) {
+        statement.setNCharacterStream(index, new StringReader((String) value));
+        return true;
+      } else if (colDef.type() == Types.NVARCHAR || colDef.type() == Types.NCHAR) {
+        statement.setNString(index, (String) value);
+        return true;
+      } else {
+        return super.maybeBindPrimitive(statement, index, schema, value);
+      }
+    }
+
+    if (schema.getFieldType() == FieldType.BYTES && colDef.type() == Types.BLOB) {
+      if (value instanceof ByteBuffer) {
+        statement.setBlob(index, new ByteArrayInputStream(((ByteBuffer) value).array()));
+      } else if (value instanceof byte[]) {
+        statement.setBlob(index, new ByteArrayInputStream((byte[]) value));
+      } else {
+        return super.maybeBindPrimitive(statement, index, schema, value);
+      }
+      return true;
+    }
+    return super.maybeBindPrimitive(statement, index, schema, value);
+  }
+
+  @SuppressWarnings("checkstyle:CyclomaticComplexity")
+  @Override
+  protected String getSqlType(SinkRecordField field) {
+    if (field.schemaName() != null) {

Review Comment:
   useless code



##########
connectors/rocketmq-connect-jdbc/src/main/java/org/apache/rocketmq/connect/jdbc/dialect/impl/OracleDatabaseDialect.java:
##########
@@ -0,0 +1,308 @@
+/*
+ * Copyright 2018 Confluent Inc.

Review Comment:
   error license



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org