use of org.apache.hadoop.hive.serde2.objectinspector.InspectableObject in project hive by apache.
the class TestOperators method testMapOperator.
public void testMapOperator() throws Throwable {
try {
System.out.println("Testing Map Operator");
// initialize configuration
JobConf hconf = new JobConf(TestOperators.class);
hconf.set(MRJobConfig.MAP_INPUT_FILE, "hdfs:///testDir/testFile");
IOContextMap.get(hconf).setInputPath(new Path("hdfs:///testDir/testFile"));
// initialize pathToAliases
ArrayList<String> aliases = new ArrayList<String>();
aliases.add("a");
aliases.add("b");
LinkedHashMap<Path, ArrayList<String>> pathToAliases = new LinkedHashMap<>();
pathToAliases.put(new Path("hdfs:///testDir"), aliases);
// initialize pathToTableInfo
// Default: treat the table as a single column "col"
TableDesc td = Utilities.defaultTd;
PartitionDesc pd = new PartitionDesc(td, null);
LinkedHashMap<Path, org.apache.hadoop.hive.ql.plan.PartitionDesc> pathToPartitionInfo = new LinkedHashMap<>();
pathToPartitionInfo.put(new Path("hdfs:///testDir"), pd);
// initialize aliasToWork
CompilationOpContext ctx = new CompilationOpContext();
CollectDesc cd = new CollectDesc(Integer.valueOf(1));
CollectOperator cdop1 = (CollectOperator) OperatorFactory.get(ctx, CollectDesc.class);
cdop1.setConf(cd);
CollectOperator cdop2 = (CollectOperator) OperatorFactory.get(ctx, CollectDesc.class);
cdop2.setConf(cd);
LinkedHashMap<String, Operator<? extends OperatorDesc>> aliasToWork = new LinkedHashMap<String, Operator<? extends OperatorDesc>>();
aliasToWork.put("a", cdop1);
aliasToWork.put("b", cdop2);
// initialize mapredWork
MapredWork mrwork = new MapredWork();
mrwork.getMapWork().setPathToAliases(pathToAliases);
mrwork.getMapWork().setPathToPartitionInfo(pathToPartitionInfo);
mrwork.getMapWork().setAliasToWork(aliasToWork);
// get map operator and initialize it
MapOperator mo = new MapOperator(new CompilationOpContext());
mo.initializeAsRoot(hconf, mrwork.getMapWork());
Text tw = new Text();
InspectableObject io1 = new InspectableObject();
InspectableObject io2 = new InspectableObject();
for (int i = 0; i < 5; i++) {
String answer = "[[" + i + ", " + (i + 1) + ", " + (i + 2) + "]]";
tw.set("" + i + "" + (i + 1) + "" + (i + 2));
mo.process(tw);
cdop1.retrieve(io1);
cdop2.retrieve(io2);
System.out.println("io1.o.toString() = " + io1.o.toString());
System.out.println("io2.o.toString() = " + io2.o.toString());
System.out.println("answer.toString() = " + answer.toString());
assertEquals(answer.toString(), io1.o.toString());
assertEquals(answer.toString(), io2.o.toString());
}
System.out.println("Map Operator ok");
} catch (Throwable e) {
e.printStackTrace();
throw (e);
}
}
use of org.apache.hadoop.hive.serde2.objectinspector.InspectableObject in project hive by apache.
the class MapredLocalTask method startForward.
private void startForward(boolean inputFileChangeSenstive, String bigTableBucket) throws Exception {
for (Operator<?> source : work.getAliasToWork().values()) {
source.reset();
}
if (inputFileChangeSenstive) {
execContext.setCurrentBigBucketFile(bigTableBucket);
}
for (Map.Entry<String, FetchOperator> entry : fetchOperators.entrySet()) {
String alias = entry.getKey();
FetchOperator fetchOp = entry.getValue();
if (inputFileChangeSenstive) {
fetchOp.clearFetchContext();
setUpFetchOpContext(fetchOp, alias, bigTableBucket);
}
// get the root operator
Operator<? extends OperatorDesc> forwardOp = work.getAliasToWork().get(alias);
// walk through the operator tree
while (!forwardOp.getDone()) {
InspectableObject row = fetchOp.getNextRow();
if (row == null) {
break;
}
forwardOp.process(row.o, 0);
}
forwardOp.flush();
}
for (Operator<?> source : work.getAliasToWork().values()) {
source.close(false);
}
}
use of org.apache.hadoop.hive.serde2.objectinspector.InspectableObject in project SQLWindowing by hbutani.
the class QueryOutputPrinter method printQueryOutput.
@SuppressWarnings({ "unchecked", "rawtypes" })
public void printQueryOutput(QueryDef qry, HiveConf cfg) throws WindowingException {
try {
JobConf jCfg = new JobConf(cfg);
SerDe outSerDe = setupOutputSerDe(qry, jCfg);
RowSchema rSchema = getQueryOutputRowSchema(qry, jCfg);
TableDesc tDesc = setupTableDesc(rSchema);
tDesc.setDeserializerClass(qry.getOutput().getSerDe().getClass());
String outputFormatClassName = qry.getOutput().getSpec().getOutputFormatClass();
Class<? extends OutputFormat> outputFormatClass = (outputFormatClassName != null) ? (Class<? extends OutputFormat>) Class.forName(outputFormatClassName) : SequenceFileOutputFormat.class;
// todo this is hack; check how this is done in Hive
tDesc.setInputFileFormatClass(mapToInputFormat(outputFormatClass));
tDesc.setProperties(qry.getOutput().getSpec().getSerDeProps());
FetchOperator ftOp = setupFetchOperator(qry, tDesc, jCfg);
while (true) {
InspectableObject io = ftOp.getNextRow();
if (io == null) {
return;
}
String s = ((Text) outSerDe.serialize(io.o, io.oi)).toString();
printOutput(s);
}
} catch (WindowingException we) {
throw we;
} catch (Exception e) {
throw new WindowingException(e);
}
}
use of org.apache.hadoop.hive.serde2.objectinspector.InspectableObject in project hive by apache.
the class SMBMapJoinOperator method fetchOneRow.
private void fetchOneRow(byte tag) {
String table = tagToAlias[tag];
MergeQueue mergeQueue = aliasToMergeQueue.get(table);
// The operator tree till the sink operator has already been processed while
// fetching the next row to fetch from the priority queue (possibly containing
// multiple files in the small table given a file in the big table). Now, process
// the remaining tree. Look at comments in DummyStoreOperator for additional
// explanation.
Operator<? extends OperatorDesc> forwardOp = conf.getAliasToSink().get(table).getChildOperators().get(0);
try {
InspectableObject row = mergeQueue.getNextRow();
if (row == null) {
fetchDone[tag] = true;
return;
}
forwardOp.process(row.o, tag);
// execution
if (forwardOp.getDone()) {
fetchDone[tag] = true;
}
} catch (Throwable e) {
if (e instanceof OutOfMemoryError) {
// Don't create a new object if we are already out of memory
throw (OutOfMemoryError) e;
} else {
throw new RuntimeException("Map local work failed", e);
}
}
}
use of org.apache.hadoop.hive.serde2.objectinspector.InspectableObject in project hive by apache.
the class BaseScalarUdfTest method testUdf.
/**
* This method drives the test. It takes the data from getBaseTable() and
* feeds it through a SELECT operator with a COLLECT operator after. Each
* row that is produced by the collect operator is compared to getExpectedResult()
* and if every row is the expected result the method completes without asserting.
* @throws HiveException
*/
public final void testUdf() throws HiveException {
InspectableObject[] data = getBaseTable();
List<ExprNodeDesc> expressionList = getExpressionList();
SelectDesc selectCtx = new SelectDesc(expressionList, OperatorTestUtils.createOutputColumnNames(expressionList));
Operator<SelectDesc> op = OperatorFactory.get(new CompilationOpContext(), SelectDesc.class);
op.setConf(selectCtx);
CollectDesc cd = new CollectDesc(Integer.valueOf(10));
CollectOperator cdop = (CollectOperator) OperatorFactory.getAndMakeChild(cd, op);
op.initialize(new JobConf(OperatorTestUtils.class), new ObjectInspector[] { data[0].oi });
OperatorTestUtils.assertResults(op, cdop, data, getExpectedResult());
}
Aggregations