Class LogMinerDmlParser
- java.lang.Object
-
- io.debezium.connector.oracle.logminer.parser.LogMinerDmlParser
-
- All Implemented Interfaces:
DmlParser
public class LogMinerDmlParser extends Object implements DmlParser
A simple DML parser implementation specifically for Oracle LogMiner. The syntax of each DML operation is restricted to the format generated by Oracle LogMiner. The following are examples of each expected syntax:insert into "schema"."table"("C1","C2") values ('v1','v2'); update "schema"."table" set "C1" = 'v1a', "C2" = 'v2a' where "C1" = 'v1' and "C2" = 'v2'; delete from "schema"."table" where "C1" = 'v1' AND "C2" = 'v2';Certain data types are not emitted as string literals, such asDATEandTIMESTAMP. For these data types, they're emitted as function calls. The parser can detect this use case and will emit the values for such columns as the explicit function call. Lets take the followingUPDATEstatement:update "schema"."table" set "C1" = TO_TIMESTAMP('2020-02-02 00:00:00', 'YYYY-MM-DD HH24:MI:SS') where "C1" = TO_TIMESTAMP('2020-02-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS');The new value forC1would beTO_TIMESTAMP('2020-02-02 00:00:00', 'YYYY-MM-DD HH24:MI:SS'). The old value forC1would beTO_TIMESTAMP('2020-02-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS').- Author:
- Chris Cranford
-
-
Field Summary
Fields Modifier and Type Field Description private static StringANDprivate static StringDELETE_FROMprivate static intDELETE_FROM_LENGTHprivate static StringINSERT_INTOprivate static intINSERT_INTO_LENGTHprivate static StringIS_NULLprivate static StringNULLprivate static StringORprivate static StringSETprivate static intSET_LENGTHprivate static StringSINGLE_QUOTEprivate static StringUNSUPPORTEDprivate static StringUNSUPPORTED_TYPEprivate static StringUPDATEprivate static intUPDATE_LENGTHprivate static StringVALUESprivate static intVALUES_LENGTHprivate static StringWHEREprivate static intWHERE_LENGTH
-
Constructor Summary
Constructors Constructor Description LogMinerDmlParser()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static LogMinerColumnValuecreateColumnValue(String columnName, String columnValue)Helper method to create aLogMinerColumnValuefrom a column name/value pair.private static <K,V>
Map<K,V>createMap(List<K> keys, List<V> values)LogMinerDmlEntryparse(String sql, Table table, String txId)Parse a DML SQL string from the LogMiner event stream.private intparseColumnListClause(String sql, int start, List<String> columnNames)Parse anINSERTstatement's column-list clause.private intparseColumnValuesClause(String sql, int start, List<String> columnValues)Parse anINSERTstatement's column-values clause.private LogMinerDmlEntryparseDelete(String sql, Table table)Parses a SQLDELETEstatement.private LogMinerDmlEntryparseInsert(String sql, Table table)Parse anINSERTSQL statement.private intparseSetClause(String sql, int start, List<String> columnNames, List<String> columnValues)Parse anUPDATEstatement'sSETclause.private intparseTableName(String sql, int index)Parses a table-name in the SQL clauseprivate LogMinerDmlEntryparseUpdate(String sql, Table table)Parse anUPDATESQL statement.private intparseWhereClause(String sql, int start, List<String> columnNames, List<String> columnValues)Parses aWHEREclause populates the provided column names and values arrays.private static StringremoveSingleQuotes(String text)Remove'quotes from around the provided text if they exist; otherwise the value is returned as-is.
-
-
-
Field Detail
-
SINGLE_QUOTE
private static final String SINGLE_QUOTE
- See Also:
- Constant Field Values
-
NULL
private static final String NULL
- See Also:
- Constant Field Values
-
INSERT_INTO
private static final String INSERT_INTO
- See Also:
- Constant Field Values
-
UPDATE
private static final String UPDATE
- See Also:
- Constant Field Values
-
DELETE_FROM
private static final String DELETE_FROM
- See Also:
- Constant Field Values
-
AND
private static final String AND
- See Also:
- Constant Field Values
-
OR
private static final String OR
- See Also:
- Constant Field Values
-
SET
private static final String SET
- See Also:
- Constant Field Values
-
WHERE
private static final String WHERE
- See Also:
- Constant Field Values
-
VALUES
private static final String VALUES
- See Also:
- Constant Field Values
-
IS_NULL
private static final String IS_NULL
- See Also:
- Constant Field Values
-
UNSUPPORTED
private static final String UNSUPPORTED
- See Also:
- Constant Field Values
-
UNSUPPORTED_TYPE
private static final String UNSUPPORTED_TYPE
- See Also:
- Constant Field Values
-
INSERT_INTO_LENGTH
private static final int INSERT_INTO_LENGTH
-
UPDATE_LENGTH
private static final int UPDATE_LENGTH
-
DELETE_FROM_LENGTH
private static final int DELETE_FROM_LENGTH
-
VALUES_LENGTH
private static final int VALUES_LENGTH
-
SET_LENGTH
private static final int SET_LENGTH
-
WHERE_LENGTH
private static final int WHERE_LENGTH
-
-
Method Detail
-
parse
public LogMinerDmlEntry parse(String sql, Table table, String txId)
Description copied from interface:DmlParserParse a DML SQL string from the LogMiner event stream.
-
parseInsert
private LogMinerDmlEntry parseInsert(String sql, Table table)
Parse anINSERTSQL statement.- Parameters:
sql- the sql statementtable- the table- Returns:
- the parsed DML entry record or
nullif the SQL was not parsed
-
parseUpdate
private LogMinerDmlEntry parseUpdate(String sql, Table table)
Parse anUPDATESQL statement.- Parameters:
sql- the sql statementtable- the table- Returns:
- the parsed DML entry record or
nullif the SQL was not parsed
-
parseDelete
private LogMinerDmlEntry parseDelete(String sql, Table table)
Parses a SQLDELETEstatement.- Parameters:
sql- the sql statementtable- the table- Returns:
- the parsed DML entry record or
nullif the SQL was not parsed
-
parseTableName
private int parseTableName(String sql, int index)
Parses a table-name in the SQL clause- Parameters:
sql- the sql statementindex- the index into the sql statement to begin parsing- Returns:
- the index into the sql string where the table name ended
-
parseColumnListClause
private int parseColumnListClause(String sql, int start, List<String> columnNames)
Parse anINSERTstatement's column-list clause.- Parameters:
sql- the sql statementstart- the index into the sql statement to begin parsingcolumnNames- the list that will be populated with the column names- Returns:
- the index into the sql string where the column-list clause ended
-
parseColumnValuesClause
private int parseColumnValuesClause(String sql, int start, List<String> columnValues)
Parse anINSERTstatement's column-values clause.- Parameters:
sql- the sql statementstart- the index into the sql statement to begin parsingcolumnValues- the list of that will populated with the column values- Returns:
- the index into the sql string where the column-values clause ended
-
parseSetClause
private int parseSetClause(String sql, int start, List<String> columnNames, List<String> columnValues)
Parse anUPDATEstatement'sSETclause.- Parameters:
sql- the sql statementstart- the index into the sql statement to begin parsingcolumnNames- the list of the changed column names that will be populatedcolumnValues- the list of the changed column values that will be populated- Returns:
- the index into the sql string where the set-clause ended
-
parseWhereClause
private int parseWhereClause(String sql, int start, List<String> columnNames, List<String> columnValues)
Parses aWHEREclause populates the provided column names and values arrays.- Parameters:
sql- the sql statementstart- the index into the sql statement to begin parsingcolumnNames- the column names parsed from the clausecolumnValues- the column values parsed from the clause- Returns:
- the index into the sql string to continue parsing
-
removeSingleQuotes
private static String removeSingleQuotes(String text)
Remove'quotes from around the provided text if they exist; otherwise the value is returned as-is.- Parameters:
text- the text to remove single quotes- Returns:
- the text with single quotes removed
-
createColumnValue
private static LogMinerColumnValue createColumnValue(String columnName, String columnValue)
Helper method to create aLogMinerColumnValuefrom a column name/value pair.- Parameters:
columnName- the column namecolumnValue- the column value- Returns:
- the LogMiner column value object
-
-