Search in sources :

Example 1 with SelectDef

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

the class QueryDefWalker method walk.

/**
	 * Visit all the columns in the select list 
	 * to setup their OIs and evaluators
	 * @param select
	 * @throws WindowingException
	 */
protected void walk(SelectDef select) throws WindowingException {
    ArrayList<ColumnDef> cols = select.getColumns();
    if (cols != null) {
        for (ColumnDef col : cols) {
            visitor.visit(col);
        }
    }
    visitor.visit(select);
}
Also used : ColumnDef(com.sap.hadoop.windowing.query2.definition.ColumnDef) OrderColumnDef(com.sap.hadoop.windowing.query2.definition.OrderColumnDef)

Example 2 with SelectDef

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

the class OutputTranslation method setupOutputSerDe.

@SuppressWarnings("unchecked")
public static void setupOutputSerDe(HiveConf hCfg, SelectDef selectDef, QueryOutputDef oDef) throws WindowingException {
    String serDeClassName = oDef.getSpec().getSerDeClass();
    Properties serDeProps = oDef.getSpec().getSerDeProps();
    Class<? extends SerDe> serDeClass;
    SerDe serde;
    try {
        serDeClass = (Class<? extends SerDe>) Class.forName(serDeClassName);
        serde = serDeClass.newInstance();
    } catch (Exception e) {
        throw new WindowingException("Internal error, initializing output SerDe", e);
    }
    StringBuilder colNames = new StringBuilder();
    StringBuilder colTypes = new StringBuilder();
    boolean first = true;
    for (ColumnDef cDef : selectDef.getColumns()) {
        if (!first) {
            colNames.append(",");
            colTypes.append(",");
        } else
            first = false;
        colNames.append(cDef.getAlias());
        colTypes.append(TypeInfoUtils.getTypeInfoFromObjectInspector(cDef.getOI()).getTypeName());
    }
    serDeProps.setProperty(org.apache.hadoop.hive.serde.Constants.LIST_COLUMNS, colNames.toString());
    serDeProps.setProperty(org.apache.hadoop.hive.serde.Constants.LIST_COLUMN_TYPES, colTypes.toString());
    try {
        serde.initialize(hCfg, serDeProps);
    } catch (SerDeException se) {
        throw new WindowingException("Failed to initialize output SerDe", se);
    }
    oDef.setSerDe(serde);
}
Also used : SerDe(org.apache.hadoop.hive.serde2.SerDe) WindowingException(com.sap.hadoop.windowing.WindowingException) ColumnDef(com.sap.hadoop.windowing.query2.definition.ColumnDef) Properties(java.util.Properties) WindowingException(com.sap.hadoop.windowing.WindowingException) SerDeException(org.apache.hadoop.hive.serde2.SerDeException) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) SerDeException(org.apache.hadoop.hive.serde2.SerDeException)

Example 3 with SelectDef

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

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

the class TranslateUtils method setupSelectOI.

/**
	 * Use the column aliases and OIs on each ColumnDef 
	 * to recreate the OI on the select list
	 * @param sDef
	 */
public static void setupSelectOI(SelectDef sDef) {
    ArrayList<ColumnDef> selColDefs = sDef.getColumns();
    ArrayList<String> colAliases = new ArrayList<String>();
    ArrayList<ObjectInspector> colOIs = new ArrayList<ObjectInspector>();
    for (ColumnDef colDef : selColDefs) {
        colAliases.add(colDef.getAlias());
        colOIs.add(colDef.getOI());
    }
    sDef.setOI(ObjectInspectorFactory.getStandardStructObjectInspector(colAliases, colOIs));
}
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) ArrayList(java.util.ArrayList) ColumnDef(com.sap.hadoop.windowing.query2.definition.ColumnDef) OrderColumnDef(com.sap.hadoop.windowing.query2.definition.OrderColumnDef)

Aggregations

ColumnDef (com.sap.hadoop.windowing.query2.definition.ColumnDef)4 OrderColumnDef (com.sap.hadoop.windowing.query2.definition.OrderColumnDef)2 WindowingException (com.sap.hadoop.windowing.WindowingException)1 QueryInputDef (com.sap.hadoop.windowing.query2.definition.QueryInputDef)1 SelectDef (com.sap.hadoop.windowing.query2.definition.SelectDef)1 SelectSpec (com.sap.hadoop.windowing.query2.specification.SelectSpec)1 InputInfo (com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)1 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)1 SerDe (org.apache.hadoop.hive.serde2.SerDe)1 SerDeException (org.apache.hadoop.hive.serde2.SerDeException)1 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)1 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)1 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)1