Search in sources :

Example 6 with QueryTranslationInfo

use of com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo in project SQLWindowing by hbutani.

the class OutputTranslation method translate.

public static void translate(QueryDef qDef) throws WindowingException {
    QueryTranslationInfo tInfo = qDef.getTranslationInfo();
    translateSelectExprs(qDef);
    validateOutputSpec(qDef);
    QueryOutputDef oDef = new QueryOutputDef();
    oDef.setOutputSpec(qDef.getSpec().getOutput());
    qDef.setOutput(oDef);
    setupOutputSerDe(tInfo.getHiveCfg(), qDef.getSelectList(), oDef);
}
Also used : QueryOutputDef(com.sap.hadoop.windowing.query2.definition.QueryOutputDef)

Example 7 with QueryTranslationInfo

use of com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo in project SQLWindowing by hbutani.

the class OutputTranslation method validateOutputSpec.

public static void validateOutputSpec(QueryDef qDef) throws WindowingException {
    QueryTranslationInfo tInfo = qDef.getTranslationInfo();
    QueryOutputSpec spec = qDef.getSpec().getOutput();
    // ensure outputPath is specified. It is optional in grammar because it is not required in Hive mode.
    if (spec == null || spec.getPath() == null) {
        throw new WindowingException("Query doesn't contain an output Path for results");
    }
    // if tableName is specified; validate it exists
    Table oTbl = null;
    if (spec.getHiveTable() != null) {
        oTbl = getHiveTableDetails(tInfo.getHiveCfg(), spec.getHiveTable(), qDef.getInput().getHiveTableSpec());
    }
    // validate serDeClass
    if (spec.getSerDeClass() == null) {
        if (oTbl != null && oTbl.getSd().getSerdeInfo().isSetSerializationLib()) {
            spec.setSerDeClass(oTbl.getSd().getSerdeInfo().getSerializationLib());
            if (oTbl.getSd().getSerdeInfo().isSetParameters()) {
                Iterator<Map.Entry<String, String>> props = oTbl.getSd().getSerdeInfo().getParameters().entrySet().iterator();
                while (props.hasNext()) {
                    Map.Entry<String, String> e = props.next();
                    spec.addSerdeProperty(e.getKey(), e.getValue());
                }
            }
        } else {
            spec.setSerDeClass(com.sap.hadoop.windowing.Constants.DEFAULT_SERDE_CLASSNAME);
            spec.addSerdeProperty(org.apache.hadoop.hive.serde.Constants.FIELD_DELIM, ",");
        }
    }
    try {
        Class.forName(spec.getSerDeClass());
    } catch (Throwable t) {
        throw new WindowingException(sprintf("Unknown SerDe Class %s", spec.getSerDeClass()), t);
    }
    // validate outputFormat
    if (spec.getOutputFormatClass() == null) {
        if (oTbl != null) {
            spec.setOutputFormatClass(oTbl.getSd().getOutputFormat());
        } else {
            spec.setOutputFormatClass(Constants.DEFAULT_OUTPUTFORMAT_CLASSNAME);
        }
    }
    try {
        Class.forName(spec.getOutputFormatClass());
    } catch (Throwable t) {
        throw new WindowingException(sprintf("Unknown OutputFormat Class %s", spec.getOutputFormatClass()), t);
    }
    // ensure user has not specified a FormatClass
    if (spec.getRecordWriterClass() != null) {
        throw new WindowingException("Illegal Output Spec: RecordWriter class not valid in MR mode");
    }
}
Also used : Table(org.apache.hadoop.hive.metastore.api.Table) QueryOutputSpec(com.sap.hadoop.windowing.query2.specification.QueryOutputSpec) WindowingException(com.sap.hadoop.windowing.WindowingException) Map(java.util.Map)

Example 8 with QueryTranslationInfo

use of com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo 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)

Example 9 with QueryTranslationInfo

use of com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo in project SQLWindowing by hbutani.

the class WindowFunctionTranslation method translate.

public static WindowFunctionDef translate(QueryDef qDef, TableFuncDef windowTableFnDef, WindowFunctionSpec wFnSpec) throws WindowingException {
    QueryTranslationInfo tInfo = qDef.getTranslationInfo();
    InputInfo iInfo = tInfo.getInputInfo(windowTableFnDef.getInput());
    WindowFunctionDef wFnDef = new WindowFunctionDef();
    wFnDef.setSpec(wFnSpec);
    /*
		 * translate args
		 */
    ArrayList<ASTNode> args = wFnSpec.getArgs();
    if (args != null) {
        for (ASTNode expr : args) {
            ArgDef argDef = translateWindowFunctionArg(qDef, windowTableFnDef, iInfo, expr);
            wFnDef.addArg(argDef);
        }
    }
    if (RANKING_FUNCS.contains(wFnSpec.getName())) {
        setupRankingArgs(qDef, windowTableFnDef, wFnDef, wFnSpec);
    }
    WindowDef wDef = translateWindowSpec(qDef, iInfo, wFnSpec);
    wFnDef.setWindow(wDef);
    validateWindowDefForWFn(windowTableFnDef, wFnDef);
    setupEvaluator(wFnDef);
    return wFnDef;
}
Also used : InputInfo(com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo) WindowDef(com.sap.hadoop.windowing.query2.definition.WindowDef) ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode) WindowFunctionDef(com.sap.hadoop.windowing.query2.definition.WindowFunctionDef) ArgDef(com.sap.hadoop.windowing.query2.definition.ArgDef)

Example 10 with QueryTranslationInfo

use of com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo in project SQLWindowing by hbutani.

the class LocalExecutor method execute.

public void execute(QueryDef qDef, WindowingShell wShell) throws WindowingException {
    QueryTranslationInfo tInfo = qDef.getTranslationInfo();
    HiveTableSpec hvTblSpec = qDef.getInput().getHiveTableSpec();
    WindowingInput wIn = IOUtils.createTableWindowingInput(hvTblSpec.getDbName(), hvTblSpec.getTableName(), tInfo.getHiveCfg());
    // Partition p = IOUtils.createPartition(partClassName, partMemSize, wIn);
    PartitionsIterator partsItr = new PartitionsIterator(wIn, qDef);
    while (partsItr.hasNext()) {
        Partition p = partsItr.next();
        Partition oP = executeChain(qDef, p);
        // IOUtils.dumpPartition(oP, System.out);
        executeSelectList(qDef, oP, new SysOutRS(out));
    }
}
Also used : QueryTranslationInfo(com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo) HiveTableSpec(com.sap.hadoop.windowing.query2.specification.HiveTableSpec) WindowingInput(com.sap.hadoop.windowing.io.WindowingInput)

Aggregations

InputInfo (com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo)6 WindowingException (com.sap.hadoop.windowing.WindowingException)4 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)4 QueryInputDef (com.sap.hadoop.windowing.query2.definition.QueryInputDef)3 TableFunctionEvaluator (com.sap.hadoop.windowing.functions2.TableFunctionEvaluator)2 ArgDef (com.sap.hadoop.windowing.query2.definition.ArgDef)2 QueryTranslationInfo (com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo)2 GenericUDFLeadLag (com.sap.hadoop.windowing.functions2.GenericUDFLeadLag)1 TableFunctionResolver (com.sap.hadoop.windowing.functions2.TableFunctionResolver)1 WindowingInput (com.sap.hadoop.windowing.io.WindowingInput)1 ColumnDef (com.sap.hadoop.windowing.query2.definition.ColumnDef)1 QueryDef (com.sap.hadoop.windowing.query2.definition.QueryDef)1 QueryOutputDef (com.sap.hadoop.windowing.query2.definition.QueryOutputDef)1 SelectDef (com.sap.hadoop.windowing.query2.definition.SelectDef)1 TableFuncDef (com.sap.hadoop.windowing.query2.definition.TableFuncDef)1 WhereDef (com.sap.hadoop.windowing.query2.definition.WhereDef)1 WindowDef (com.sap.hadoop.windowing.query2.definition.WindowDef)1 WindowFunctionDef (com.sap.hadoop.windowing.query2.definition.WindowFunctionDef)1 HiveTableSpec (com.sap.hadoop.windowing.query2.specification.HiveTableSpec)1 QueryOutputSpec (com.sap.hadoop.windowing.query2.specification.QueryOutputSpec)1