Search in sources :

Example 1 with HiveTableSpec

use of com.sap.hadoop.windowing.query2.specification.HiveTableSpec in project SQLWindowing by hbutani.

the class InputTranslation method translate.

private static HiveQueryDef translate(QueryDef qDef, HiveQuerySpec spec) throws WindowingException {
    HiveQueryDef def = new HiveQueryDef();
    HiveQueryExecutor hiveQryExec = qDef.getTranslationInfo().getHiveQueryExecutor();
    Hive hive = qDef.getTranslationInfo().getHive();
    String tableName = hiveQryExec.createTableAsQuery(spec.getHiveQuery());
    HiveTableSpec tSpec = new HiveTableSpec();
    tSpec.setDbName(hive.getCurrentDatabase());
    tSpec.setTableName(tableName);
    tSpec.setPartition(spec.getPartition());
    tSpec.setOrder(spec.getOrder());
    def = (HiveQueryDef) InputTranslation.translate(qDef, tSpec, (HiveTableDef) def);
    return def;
}
Also used : HiveQueryExecutor(com.sap.hadoop.windowing.runtime2.HiveQueryExecutor) Hive(org.apache.hadoop.hive.ql.metadata.Hive) HiveQueryDef(com.sap.hadoop.windowing.query2.definition.HiveQueryDef) HiveTableSpec(com.sap.hadoop.windowing.query2.specification.HiveTableSpec)

Example 2 with HiveTableSpec

use of com.sap.hadoop.windowing.query2.specification.HiveTableSpec in project SQLWindowing by hbutani.

the class InputTranslation method getTableAlias.

private static String getTableAlias(QueryDef qDef, int inputNum, QueryInputDef inputDef) throws WindowingException {
    if (inputDef instanceof HiveTableDef) {
        HiveTableDef hTbldef = (HiveTableDef) inputDef;
        String db = ((HiveTableSpec) hTbldef.getSpec()).getDbName();
        String tableName = ((HiveTableSpec) hTbldef.getSpec()).getTableName();
        return db + "." + tableName;
    } else if (inputDef instanceof TableFuncDef) {
        return "ptf_" + inputNum;
    }
    throw new WindowingException(sprintf("Internal Error: attempt to translate %s", inputDef.getSpec()));
}
Also used : WindowingException(com.sap.hadoop.windowing.WindowingException) HiveTableSpec(com.sap.hadoop.windowing.query2.specification.HiveTableSpec) HiveTableDef(com.sap.hadoop.windowing.query2.definition.HiveTableDef) TableFuncDef(com.sap.hadoop.windowing.query2.definition.TableFuncDef)

Example 3 with HiveTableSpec

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

use of com.sap.hadoop.windowing.query2.specification.HiveTableSpec in project SQLWindowing by hbutani.

the class LocalExecutor method execute.

public void execute(QueryDef qDef, WindowingShell wShell) throws WindowingException {
    QueryTranslationInfo tInfo = qDef.getTranslationInfo();
    HiveTableSpec hvTblSpec = qDef.getInput().getHiveTableSpec();
    WindowingInput wIn = IOUtils.createTableWindowingInput(hvTblSpec.getDbName(), hvTblSpec.getTableName(), tInfo.getHiveCfg());
    //Partition p = IOUtils.createPartition(partClassName, partMemSize, wIn);
    PartitionsIterator partsItr = new PartitionsIterator(wIn, qDef);
    while (partsItr.hasNext()) {
        Partition p = partsItr.next();
        Partition oP = executeChain(qDef, p);
        //IOUtils.dumpPartition(oP, System.out);
        executeSelectList(qDef, oP, new SysOutRS(out));
    }
}
Also used : QueryTranslationInfo(com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo) HiveTableSpec(com.sap.hadoop.windowing.query2.specification.HiveTableSpec) WindowingInput(com.sap.hadoop.windowing.io.WindowingInput)

Aggregations

HiveTableSpec (com.sap.hadoop.windowing.query2.specification.HiveTableSpec)3 WindowingException (com.sap.hadoop.windowing.WindowingException)2 HiveTableDef (com.sap.hadoop.windowing.query2.definition.HiveTableDef)2 Hive (org.apache.hadoop.hive.ql.metadata.Hive)2 WindowingInput (com.sap.hadoop.windowing.io.WindowingInput)1 HiveQueryDef (com.sap.hadoop.windowing.query2.definition.HiveQueryDef)1 TableFuncDef (com.sap.hadoop.windowing.query2.definition.TableFuncDef)1 QueryTranslationInfo (com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo)1 HiveQueryExecutor (com.sap.hadoop.windowing.runtime2.HiveQueryExecutor)1 HiveMetaStoreClient (org.apache.hadoop.hive.metastore.HiveMetaStoreClient)1 StorageDescriptor (org.apache.hadoop.hive.metastore.api.StorageDescriptor)1 Table (org.apache.hadoop.hive.metastore.api.Table)1 Deserializer (org.apache.hadoop.hive.serde2.Deserializer)1