private void resolveColumnDataType()

in seatunnel-connectors-v2/connector-cdc/connector-cdc-oracle/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/oracle/source/parser/CustomColumnDefinitionParserListener.java [93:254]


    private void resolveColumnDataType(PlSqlParser.DatatypeContext ctx) {
        // If the context is null, there is nothing this method can resolve and it is safe to return
        if (ctx == null) {
            return;
        }

        if (ctx.native_datatype_element() != null) {
            PlSqlParser.Precision_partContext precisionPart = ctx.precision_part();
            if (ctx.native_datatype_element().INT() != null
                    || ctx.native_datatype_element().INTEGER() != null
                    || ctx.native_datatype_element().SMALLINT() != null
                    || ctx.native_datatype_element().NUMERIC() != null
                    || ctx.native_datatype_element().DECIMAL() != null) {
                // NUMERIC and DECIMAL types have by default zero scale
                columnEditor.jdbcType(Types.NUMERIC).type("NUMBER");

                if (precisionPart != null) {
                    setPrecision(precisionPart, columnEditor);
                    setScale(precisionPart, columnEditor);
                }
            } else if (ctx.native_datatype_element().DATE() != null) {
                // JDBC driver reports type as timestamp but name DATE
                columnEditor.jdbcType(Types.TIMESTAMP).type("DATE");
            } else if (ctx.native_datatype_element().TIMESTAMP() != null) {
                if (ctx.WITH() != null && ctx.TIME() != null && ctx.ZONE() != null) {
                    if (ctx.LOCAL() != null) {
                        columnEditor
                                .jdbcType(OracleTypes.TIMESTAMPLTZ)
                                .type("TIMESTAMP WITH LOCAL TIME ZONE");
                    } else {
                        columnEditor
                                .jdbcType(OracleTypes.TIMESTAMPTZ)
                                .type("TIMESTAMP WITH TIME ZONE");
                    }
                } else {
                    columnEditor.jdbcType(Types.TIMESTAMP).type("TIMESTAMP");
                }

                if (precisionPart == null) {
                    columnEditor.length(6);
                } else {
                    setPrecision(precisionPart, columnEditor);
                }
            }
            // VARCHAR is the same as VARCHAR2 in Oracle
            else if (ctx.native_datatype_element().VARCHAR2() != null
                    || ctx.native_datatype_element().VARCHAR() != null) {
                columnEditor.jdbcType(Types.VARCHAR).type("VARCHAR2");

                if (precisionPart == null) {
                    columnEditor.length(getVarCharDefaultLength());
                } else {
                    setPrecision(precisionPart, columnEditor);
                }
            } else if (ctx.native_datatype_element().NVARCHAR2() != null) {
                columnEditor.jdbcType(Types.NVARCHAR).type("NVARCHAR2");

                if (precisionPart == null) {
                    columnEditor.length(getVarCharDefaultLength());
                } else {
                    setPrecision(precisionPart, columnEditor);
                }
            } else if (ctx.native_datatype_element().CHAR() != null) {
                columnEditor.jdbcType(Types.CHAR).type("CHAR").length(1);

                if (precisionPart != null) {
                    setPrecision(precisionPart, columnEditor);
                }
            } else if (ctx.native_datatype_element().NCHAR() != null) {
                columnEditor.jdbcType(Types.NCHAR).type("NCHAR").length(1);

                if (precisionPart != null) {
                    setPrecision(precisionPart, columnEditor);
                }
            } else if (ctx.native_datatype_element().BINARY_FLOAT() != null) {
                columnEditor.jdbcType(OracleTypes.BINARY_FLOAT).type("BINARY_FLOAT");
            } else if (ctx.native_datatype_element().BINARY_DOUBLE() != null) {
                columnEditor.jdbcType(OracleTypes.BINARY_DOUBLE).type("BINARY_DOUBLE");
            }
            // PRECISION keyword is mandatory
            else if (ctx.native_datatype_element().FLOAT() != null
                    || (ctx.native_datatype_element().DOUBLE() != null
                            && ctx.native_datatype_element().PRECISION() != null)) {
                columnEditor.jdbcType(Types.FLOAT).type("FLOAT");

                // TODO float's precision is about bits not decimal digits; should be ok for now to
                // over-size
                if (precisionPart != null) {
                    setPrecision(precisionPart, columnEditor);
                }
            } else if (ctx.native_datatype_element().REAL() != null) {
                columnEditor
                        .jdbcType(Types.FLOAT)
                        .type("FLOAT")
                        // TODO float's precision is about bits not decimal digits; should be ok for
                        // now to over-size
                        .length(63);
            } else if (ctx.native_datatype_element().NUMBER() != null) {
                columnEditor.jdbcType(Types.NUMERIC).type("NUMBER");

                if (precisionPart != null) {
                    if (precisionPart.ASTERISK() != null) {
                        // when asterisk is used, explicitly set precision to 38
                        columnEditor.length(38);
                    } else {
                        setPrecision(precisionPart, columnEditor);
                    }
                    setScale(precisionPart, columnEditor);
                }
            } else if (ctx.native_datatype_element().BLOB() != null) {
                columnEditor.jdbcType(Types.BLOB).type("BLOB");
            } else if (ctx.native_datatype_element().CLOB() != null) {
                columnEditor.jdbcType(Types.CLOB).type("CLOB");
            } else if (ctx.native_datatype_element().NCLOB() != null) {
                columnEditor.jdbcType(Types.NCLOB).type("NCLOB");
            } else if (ctx.native_datatype_element().RAW() != null) {
                columnEditor.jdbcType(OracleTypes.RAW).type("RAW");

                setPrecision(precisionPart, columnEditor);
            } else if (ctx.native_datatype_element().SDO_GEOMETRY() != null) {
                // Allows the registration of new SDO_GEOMETRY columns via an CREATE/ALTER TABLE
                // This is the same registration of the column that is resolved during JDBC metadata
                // inspection.
                columnEditor.jdbcType(OracleTypes.OTHER).type("SDO_GEOMETRY").length(1);
            } else if (ctx.native_datatype_element().ROWID() != null) {
                columnEditor.jdbcType(Types.VARCHAR).type("ROWID");
            } else {
                columnEditor
                        .jdbcType(OracleTypes.OTHER)
                        .type(ctx.native_datatype_element().getText());
            }
        } else if (ctx.INTERVAL() != null
                && ctx.YEAR() != null
                && ctx.TO() != null
                && ctx.MONTH() != null) {
            columnEditor.jdbcType(OracleTypes.INTERVALYM).type("INTERVAL YEAR TO MONTH").length(2);
            if (!ctx.expression().isEmpty()) {
                columnEditor.length(Integer.valueOf((ctx.expression(0).getText())));
            }
        } else if (ctx.INTERVAL() != null
                && ctx.DAY() != null
                && ctx.TO() != null
                && ctx.SECOND() != null) {
            columnEditor
                    .jdbcType(OracleTypes.INTERVALDS)
                    .type("INTERVAL DAY TO SECOND")
                    .length(2)
                    .scale(6);
            for (final PlSqlParser.ExpressionContext e : ctx.expression()) {
                if (e.getSourceInterval().startsAfter(ctx.TO().getSourceInterval())) {
                    columnEditor.scale(Integer.valueOf(e.getText()));
                } else {
                    columnEditor.length(Integer.valueOf(e.getText()));
                }
            }
            if (!ctx.expression().isEmpty()) {
                columnEditor.length(Integer.valueOf((ctx.expression(0).getText())));
            }
        } else {
            columnEditor.jdbcType(OracleTypes.OTHER).type(ctx.getText());
        }
    }