Search in sources :

Example 1 with RelationFieldsPair

use of com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem.RelationFieldsPair in project canal by alibaba.

the class SqlParser method visitOnCondition.

/**
 * 解析on条件
 *
 * @param expr sql expr
 * @param tableItem 表对象
 */
private static void visitOnCondition(SQLExpr expr, TableItem tableItem) {
    if (!(expr instanceof SQLBinaryOpExpr)) {
        throw new UnsupportedOperationException();
    }
    SQLBinaryOpExpr sqlBinaryOpExpr = (SQLBinaryOpExpr) expr;
    if (sqlBinaryOpExpr.getOperator() == BooleanAnd) {
        visitOnCondition(sqlBinaryOpExpr.getLeft(), tableItem);
        visitOnCondition(sqlBinaryOpExpr.getRight(), tableItem);
    } else if (sqlBinaryOpExpr.getOperator() == Equality) {
        FieldItem leftFieldItem = new FieldItem();
        visitColumn(sqlBinaryOpExpr.getLeft(), leftFieldItem);
        if (leftFieldItem.getColumnItems().size() != 1 || leftFieldItem.isMethod() || leftFieldItem.isBinaryOp()) {
            throw new UnsupportedOperationException("Unsupported for complex of on-condition");
        }
        FieldItem rightFieldItem = new FieldItem();
        visitColumn(sqlBinaryOpExpr.getRight(), rightFieldItem);
        if (rightFieldItem.getColumnItems().size() != 1 || rightFieldItem.isMethod() || rightFieldItem.isBinaryOp()) {
            throw new UnsupportedOperationException("Unsupported for complex of on-condition");
        }
        tableItem.getRelationFields().add(new RelationFieldsPair(leftFieldItem, rightFieldItem));
    } else {
        throw new UnsupportedOperationException("Unsupported for complex of on-condition");
    }
}
Also used : SQLBinaryOpExpr(com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr) FieldItem(com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem.FieldItem) RelationFieldsPair(com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem.RelationFieldsPair)

Aggregations

SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)1 FieldItem (com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem.FieldItem)1 RelationFieldsPair (com.alibaba.otter.canal.client.adapter.es.core.config.SchemaItem.RelationFieldsPair)1