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);
}
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;
}
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);
}
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);
}
}
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");
}
}
Aggregations