Search in sources :

Example 1 with QueryOutputDef

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

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

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

the class MRExecutor method createOutputTableDesc.

/**
 * Use the settings on the QueryOutputDef to define the
 * properties for the output table in hive.
 * @param qDef
 * @return
 * @throws WindowingException
 */
static TableDesc createOutputTableDesc(QueryDef qDef) throws WindowingException {
    QueryOutputDef oDef = qDef.getOutput();
    Class<? extends SerDe> serDeClass = oDef.getSerDe().getClass();
    Properties p = oDef.getSpec().getSerDeProps();
    String columnNamesList = p.getProperty(Constants.LIST_COLUMNS);
    String columnTypesList = p.getProperty(Constants.LIST_COLUMN_TYPES);
    String fieldSeparator = p.getProperty(Constants.FIELD_DELIM, Integer.toString(Utilities.ctrlaCode));
    return PlanUtils.getTableDesc(serDeClass, fieldSeparator, columnNamesList, columnTypesList, false);
}
Also used : Properties(java.util.Properties) QueryOutputDef(com.sap.hadoop.windowing.query2.definition.QueryOutputDef)

Aggregations

QueryOutputDef (com.sap.hadoop.windowing.query2.definition.QueryOutputDef)2 Properties (java.util.Properties)2 WindowingException (com.sap.hadoop.windowing.WindowingException)1 ColumnDef (com.sap.hadoop.windowing.query2.definition.ColumnDef)1 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)1 SerDe (org.apache.hadoop.hive.serde2.SerDe)1 SerDeException (org.apache.hadoop.hive.serde2.SerDeException)1