zml1206 commented on code in PR #3995: URL: https://github.com/apache/flink-cdc/pull/3995#discussion_r2740507702
########## flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-oracle/src/main/java/org/apache/flink/cdc/connectors/oracle/source/parser/ColumnDefinitionParserListener.java: ########## @@ -0,0 +1,312 @@ +/* + * 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.flink.cdc.connectors.oracle.source.parser; + +import io.debezium.ddl.parser.oracle.generated.PlSqlParser; +import io.debezium.relational.ColumnEditor; +import io.debezium.relational.TableEditor; +import oracle.jdbc.OracleTypes; + +import java.sql.Types; + +/** Parser listener that parses column definitions of Oracle DDL statements. */ +public class ColumnDefinitionParserListener extends BaseParserListener { + + private final TableEditor tableEditor; + private ColumnEditor columnEditor; + + public ColumnDefinitionParserListener( + final TableEditor tableEditor, final ColumnEditor columnEditor) { + this.tableEditor = tableEditor; + this.columnEditor = columnEditor; + } + + public void setColumnEditor(ColumnEditor columnEditor) { + this.columnEditor = columnEditor; + } + + @Override + public void enterColumn_definition(PlSqlParser.Column_definitionContext ctx) { + resolveColumnDataType(ctx); + if (ctx.DEFAULT() != null) { + columnEditor.defaultValueExpression(ctx.column_default_value().getText()); + } + super.enterColumn_definition(ctx); + } + + @Override + public void enterPrimary_key_clause(PlSqlParser.Primary_key_clauseContext ctx) { + // this rule will be parsed only if no primary key is set in a table + // otherwise the statement can't be executed due to multiple primary key error + columnEditor.optional(false); + tableEditor.addColumn(columnEditor.create()); + tableEditor.setPrimaryKeyNames(columnEditor.name()); + super.enterPrimary_key_clause(ctx); + } + + @Override + public void enterModify_col_properties(PlSqlParser.Modify_col_propertiesContext ctx) { + resolveColumnDataType(ctx); Review Comment: If dataType is not specified, will changing the column attribute to nullable have no effect? -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
