Search in sources :

Example 31 with QueryDef

use of com.sap.hadoop.windowing.query2.definition.QueryDef 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 32 with QueryDef

use of com.sap.hadoop.windowing.query2.definition.QueryDef 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 33 with QueryDef

use of com.sap.hadoop.windowing.query2.definition.QueryDef 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 34 with QueryDef

use of com.sap.hadoop.windowing.query2.definition.QueryDef in project SQLWindowing by hbutani.

the class TranslateUtils method buildArgDef.

public static ArgDef buildArgDef(QueryDef qDef, InputInfo iInfo, ASTNode arg) throws WindowingException {
    ArgDef argDef = new ArgDef();
    ExprNodeDesc exprNode = TranslateUtils.buildExprNode(arg, iInfo.getTypeCheckCtx());
    ExprNodeEvaluator exprEval = WindowingExprNodeEvaluatorFactory.get(qDef.getTranslationInfo(), exprNode);
    ObjectInspector oi = initExprNodeEvaluator(qDef, exprNode, exprEval, iInfo);
    argDef.setExpression(arg);
    argDef.setExprNode(exprNode);
    argDef.setExprEvaluator(exprEval);
    argDef.setOI(oi);
    return argDef;
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ExprNodeEvaluator(org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) ArgDef(com.sap.hadoop.windowing.query2.definition.ArgDef)

Example 35 with QueryDef

use of com.sap.hadoop.windowing.query2.definition.QueryDef in project SQLWindowing by hbutani.

the class MRUtils method addPTFMapOperator.

/**
	 * Returns true if the query needs a map-side reshape. PTFOperator is added
	 * on the map-side before ReduceSinkOperator in this scenario.
	 * 
	 * @param qdef
	 * @return
	 * @throws WindowingException 
	 */
public static boolean addPTFMapOperator(QueryDef qdef) throws WindowingException {
    boolean hasMap = false;
    TableFuncDef tabDef = RuntimeUtils.getFirstTableFunction(qdef);
    TableFunctionEvaluator tEval = tabDef.getFunction();
    if (tEval.isTransformsRawInput()) {
        hasMap = true;
    }
    return hasMap;
}
Also used : TableFunctionEvaluator(com.sap.hadoop.windowing.functions2.TableFunctionEvaluator) TableFuncDef(com.sap.hadoop.windowing.query2.definition.TableFuncDef)

Aggregations

WindowingException (com.sap.hadoop.windowing.WindowingException)15 QueryDef (com.sap.hadoop.windowing.query2.definition.QueryDef)7 TableFuncDef (com.sap.hadoop.windowing.query2.definition.TableFuncDef)7 InputInfo (com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo)7 ColumnDef (com.sap.hadoop.windowing.query2.definition.ColumnDef)6 QueryInputDef (com.sap.hadoop.windowing.query2.definition.QueryInputDef)6 ExprNodeEvaluator (org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator)6 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)6 OrderColumnDef (com.sap.hadoop.windowing.query2.definition.OrderColumnDef)5 QuerySpec (com.sap.hadoop.windowing.query2.specification.QuerySpec)5 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)5 TableFunctionEvaluator (com.sap.hadoop.windowing.functions2.TableFunctionEvaluator)4 ArgDef (com.sap.hadoop.windowing.query2.definition.ArgDef)4 OrderDef (com.sap.hadoop.windowing.query2.definition.OrderDef)4 LocalExecutorTest (com.sap.hadoop.windowing.testutils.LocalExecutorTest)4 Test (org.junit.Test)4 HiveQueryDef (com.sap.hadoop.windowing.query2.definition.HiveQueryDef)3 HiveTableDef (com.sap.hadoop.windowing.query2.definition.HiveTableDef)3 HiveTableSpec (com.sap.hadoop.windowing.query2.specification.HiveTableSpec)3 ArrayList (java.util.ArrayList)3