Search in sources :

Example 1 with SqlAsOperator

use of org.apache.calcite.sql.SqlAsOperator in project samza by apache.

the class SamzaSqlQueryParser method getSource.

private static void getSource(SqlNode node, ArrayList<String> sourceList) {
    if (node instanceof SqlJoin) {
        SqlJoin joinNode = (SqlJoin) node;
        ArrayList<String> sourcesLeft = new ArrayList<>();
        ArrayList<String> sourcesRight = new ArrayList<>();
        getSource(joinNode.getLeft(), sourcesLeft);
        getSource(joinNode.getRight(), sourcesRight);
        sourceList.addAll(sourcesLeft);
        sourceList.addAll(sourcesRight);
    } else if (node instanceof SqlIdentifier) {
        sourceList.add(node.toString());
    } else if (node instanceof SqlBasicCall) {
        SqlBasicCall basicCall = (SqlBasicCall) node;
        if (basicCall.getOperator() instanceof SqlAsOperator) {
            getSource(basicCall.operand(0), sourceList);
        } else if (basicCall.getOperator() instanceof SqlUnnestOperator && basicCall.operand(0) instanceof SqlSelect) {
            sourceList.addAll(getSourcesFromSelectQuery(basicCall.operand(0)));
        }
    } else if (node instanceof SqlSelect) {
        getSource(((SqlSelect) node).getFrom(), sourceList);
    }
}
Also used : SqlSelect(org.apache.calcite.sql.SqlSelect) SqlBasicCall(org.apache.calcite.sql.SqlBasicCall) SqlJoin(org.apache.calcite.sql.SqlJoin) ArrayList(java.util.ArrayList) SqlUnnestOperator(org.apache.calcite.sql.SqlUnnestOperator) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) SqlAsOperator(org.apache.calcite.sql.SqlAsOperator)

Aggregations

ArrayList (java.util.ArrayList)1 SqlAsOperator (org.apache.calcite.sql.SqlAsOperator)1 SqlBasicCall (org.apache.calcite.sql.SqlBasicCall)1 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)1 SqlJoin (org.apache.calcite.sql.SqlJoin)1 SqlSelect (org.apache.calcite.sql.SqlSelect)1 SqlUnnestOperator (org.apache.calcite.sql.SqlUnnestOperator)1