Search in sources :

Example 46 with WindowingException

use of com.sap.hadoop.windowing.WindowingException in project SQLWindowing by hbutani.

the class SymbolParser method parse.

public void parse() throws WindowingException {
    symbols = patternStr.split("\\.");
    symbolFunctions = new ArrayList<SymbolFunction>();
    for (String symbol : symbols) {
        boolean isStar = symbol.endsWith("*");
        boolean isPlus = symbol.endsWith("+");
        symbol = (isStar || isPlus) ? symbol.substring(0, symbol.length() - 1) : symbol;
        Object[] symbolDetails = symbolExprEvalMap.get(symbol.toLowerCase());
        if (symbolDetails == null) {
            throw new WindowingException(sprintf("Unknown Symbol %s", symbol));
        }
        ExprNodeEvaluator symbolExprEval = (ExprNodeEvaluator) symbolDetails[0];
        ObjectInspector symbolExprOI = (ObjectInspector) symbolDetails[1];
        SymbolFunction sFn = new Symbol(symbolExprEval, symbolExprOI);
        if (isStar) {
            sFn = new Star(sFn);
        } else if (isPlus) {
            sFn = new Plus(sFn);
        }
        symbolFunctions.add(sFn);
    }
    symbolFnChain = new Chain(symbolFunctions);
}
Also used : Chain(com.sap.hadoop.windowing.functions2.table.npath.SymbolFunction.Chain) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) Symbol(com.sap.hadoop.windowing.functions2.table.npath.SymbolFunction.Symbol) ExprNodeEvaluator(org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator) Star(com.sap.hadoop.windowing.functions2.table.npath.SymbolFunction.Star) WindowingException(com.sap.hadoop.windowing.WindowingException) Plus(com.sap.hadoop.windowing.functions2.table.npath.SymbolFunction.Plus)

Example 47 with WindowingException

use of com.sap.hadoop.windowing.WindowingException in project SQLWindowing by hbutani.

the class InputTranslation method translate.

private static HiveTableDef translate(QueryDef qDef, HiveTableSpec spec, HiveTableDef def) throws WindowingException {
    def = def == null ? new HiveTableDef() : def;
    HiveMetaStoreClient hiveMSC = qDef.getTranslationInfo().getHiveMSClient();
    Hive hive = qDef.getTranslationInfo().getHive();
    def.setSpec(spec);
    if (spec.getDbName() == null) {
        spec.setDbName(hive.getCurrentDatabase());
    }
    try {
        Table t = hiveMSC.getTable(spec.getDbName(), spec.getTableName());
        qDef.getTranslationInfo().setTbl(TranslateUtils.getHiveMetaTable(hive, t.getDbName(), def.getHiveTableSpec().getTableName()));
        StorageDescriptor sd = t.getSd();
        def.setInputFormatClassName(sd.getInputFormat());
        def.setTableSerdeClassName(sd.getSerdeInfo().getSerializationLib());
        def.setTableSerdeProps(setupSerdeProps(qDef, sd));
        def.setLocation(sd.getLocation());
        Deserializer serde = HiveUtils.getDeserializer(qDef.getTranslationInfo().getHiveCfg(), t);
        def.setOI((StructObjectInspector) serde.getObjectInspector());
        def.setSerde((SerDe) serde);
    } catch (WindowingException we) {
        throw we;
    } catch (Exception he) {
        throw new WindowingException(he);
    }
    return def;
}
Also used : Hive(org.apache.hadoop.hive.ql.metadata.Hive) HiveMetaStoreClient(org.apache.hadoop.hive.metastore.HiveMetaStoreClient) Table(org.apache.hadoop.hive.metastore.api.Table) Deserializer(org.apache.hadoop.hive.serde2.Deserializer) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) WindowingException(com.sap.hadoop.windowing.WindowingException) WindowingException(com.sap.hadoop.windowing.WindowingException) HiveTableDef(com.sap.hadoop.windowing.query2.definition.HiveTableDef)

Example 48 with WindowingException

use of com.sap.hadoop.windowing.WindowingException 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 49 with WindowingException

use of com.sap.hadoop.windowing.WindowingException in project SQLWindowing by hbutani.

the class OutputTranslation method getHiveTableDetails.

public static Table getHiveTableDetails(HiveConf cfg, String tableName, HiveTableSpec inpTblSpec) throws WindowingException {
    try {
        String db = inpTblSpec.getDbName();
        db = db == null ? Hive.get(cfg).getCurrentDatabase() : db;
        return HiveUtils.getTable(db, tableName, cfg);
    } catch (HiveException he) {
        throw new WindowingException(he);
    }
}
Also used : HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) WindowingException(com.sap.hadoop.windowing.WindowingException)

Example 50 with WindowingException

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

Aggregations

WindowingException (com.sap.hadoop.windowing.WindowingException)62 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)18 SerDeException (org.apache.hadoop.hive.serde2.SerDeException)11 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)10 IOException (java.io.IOException)9 SerDe (org.apache.hadoop.hive.serde2.SerDe)9 ExprNodeEvaluator (org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator)8 ArrayList (java.util.ArrayList)7 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)7 HiveMetaStoreClient (org.apache.hadoop.hive.metastore.HiveMetaStoreClient)6 Properties (java.util.Properties)5 Path (org.apache.hadoop.fs.Path)5 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)5 Table (org.apache.hadoop.hive.metastore.api.Table)5 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)5 Writable (org.apache.hadoop.io.Writable)5 TableFuncDef (com.sap.hadoop.windowing.query2.definition.TableFuncDef)4 HiveConf (org.apache.hadoop.hive.conf.HiveConf)4 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)4 ArgDef (com.sap.hadoop.windowing.query2.definition.ArgDef)3