Search in sources :

Example 1 with SelectSpec

use of com.sap.hadoop.windowing.query2.specification.SelectSpec in project SQLWindowing by hbutani.

the class ParseUtils method parseSelect.

public static SelectSpec parseSelect(String selectExprStr) throws WindowingException {
    Windowing2Lexer lexer;
    CommonTokenStream tokens;
    Windowing2Parser parser = null;
    CommonTree t;
    CommonTreeNodeStream nodes;
    QSpecBuilder2 qSpecBldr = null;
    String err;
    try {
        lexer = new Windowing2Lexer(new ANTLRStringStream(selectExprStr));
        tokens = new CommonTokenStream(lexer);
        parser = new Windowing2Parser(tokens);
        parser.setTreeAdaptor(TranslateUtils.adaptor);
        t = (CommonTree) parser.select().getTree();
        err = parser.getWindowingParseErrors();
        if (err != null) {
            throw new WindowingException(err);
        }
    } catch (WindowingException we) {
        throw we;
    } catch (Throwable te) {
        err = parser.getWindowingParseErrors();
        if (err != null) {
            throw new WindowingException(err);
        }
        throw new WindowingException("Parse Error:" + te.toString(), te);
    }
    TranslateUtils.unescapeStringLiterals((ASTNode) t);
    try {
        nodes = new CommonTreeNodeStream(t);
        nodes.setTokenStream(tokens);
        qSpecBldr = new QSpecBuilder2(nodes);
        SelectSpec selectSpec = qSpecBldr.select();
        err = qSpecBldr.getWindowingParseErrors();
        if (err != null) {
            throw new WindowingException(err);
        }
        return selectSpec;
    } catch (WindowingException we) {
        throw we;
    } catch (Throwable te) {
        err = qSpecBldr.getWindowingParseErrors();
        if (err != null) {
            throw new WindowingException(err);
        }
        throw new WindowingException("Parse Error:" + te.toString(), te);
    }
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) CommonTree(org.antlr.runtime.tree.CommonTree) WindowingException(com.sap.hadoop.windowing.WindowingException) SelectSpec(com.sap.hadoop.windowing.query2.specification.SelectSpec) CommonTreeNodeStream(org.antlr.runtime.tree.CommonTreeNodeStream)

Example 2 with SelectSpec

use of com.sap.hadoop.windowing.query2.specification.SelectSpec in project SQLWindowing by hbutani.

the class OutputTranslation method translateSelectExprs.

public static void translateSelectExprs(QueryDef qDef) throws WindowingException {
    QueryTranslationInfo tInfo = qDef.getTranslationInfo();
    QueryInputDef iDef = qDef.getInput();
    InputInfo iInfo = tInfo.getInputInfo(iDef);
    SelectDef selectDef = qDef.getSelectList();
    SelectSpec selectSpec = qDef.getSpec().getSelectList();
    Iterator<Object> selectExprsAndAliases = selectSpec.getColumnListAndAlias();
    int i = 0;
    ColumnDef cDef = null;
    while (selectExprsAndAliases.hasNext()) {
        Object[] o = (Object[]) selectExprsAndAliases.next();
        boolean isWnFn = ((Boolean) o[0]).booleanValue();
        if (isWnFn) {
            cDef = translateWindowFnAlias(qDef, iInfo, i++, (String) o[1]);
        } else {
            cDef = translateSelectExpr(qDef, iInfo, i++, (String) o[1], (ASTNode) o[2]);
        }
        selectDef.addColumn(cDef);
    }
    TranslateUtils.setupSelectOI(selectDef);
}
Also used : SelectDef(com.sap.hadoop.windowing.query2.definition.SelectDef) ColumnDef(com.sap.hadoop.windowing.query2.definition.ColumnDef) SelectSpec(com.sap.hadoop.windowing.query2.specification.SelectSpec) InputInfo(com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo) QueryInputDef(com.sap.hadoop.windowing.query2.definition.QueryInputDef) ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode)

Aggregations

SelectSpec (com.sap.hadoop.windowing.query2.specification.SelectSpec)2 WindowingException (com.sap.hadoop.windowing.WindowingException)1 ColumnDef (com.sap.hadoop.windowing.query2.definition.ColumnDef)1 QueryInputDef (com.sap.hadoop.windowing.query2.definition.QueryInputDef)1 SelectDef (com.sap.hadoop.windowing.query2.definition.SelectDef)1 InputInfo (com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo)1 ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)1 CommonTokenStream (org.antlr.runtime.CommonTokenStream)1 CommonTree (org.antlr.runtime.tree.CommonTree)1 CommonTreeNodeStream (org.antlr.runtime.tree.CommonTreeNodeStream)1 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)1