use of org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PTFInputSpec in project hive by apache.
the class SemanticAnalyzer method processPTFSource.
//--------------------------- PTF handling -----------------------------------
/*
* - a partitionTableFunctionSource can be a tableReference, a SubQuery or another
* PTF invocation.
* - For a TABLEREF: set the source to the alias returned by processTable
* - For a SubQuery: set the source to the alias returned by processSubQuery
* - For a PTF invocation: recursively call processPTFChain.
*/
private PTFInputSpec processPTFSource(QB qb, ASTNode inputNode) throws SemanticException {
PTFInputSpec qInSpec = null;
int type = inputNode.getType();
String alias;
switch(type) {
case HiveParser.TOK_TABREF:
alias = processTable(qb, inputNode);
qInSpec = new PTFQueryInputSpec();
((PTFQueryInputSpec) qInSpec).setType(PTFQueryInputType.TABLE);
((PTFQueryInputSpec) qInSpec).setSource(alias);
break;
case HiveParser.TOK_SUBQUERY:
alias = processSubQuery(qb, inputNode);
qInSpec = new PTFQueryInputSpec();
((PTFQueryInputSpec) qInSpec).setType(PTFQueryInputType.SUBQUERY);
((PTFQueryInputSpec) qInSpec).setSource(alias);
break;
case HiveParser.TOK_PTBLFUNCTION:
qInSpec = processPTFChain(qb, inputNode);
break;
default:
throw new SemanticException(generateErrorMessage(inputNode, "Unknown input type to PTF"));
}
qInSpec.setAstNode(inputNode);
return qInSpec;
}
use of org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PTFInputSpec in project hive by apache.
the class PTFTranslator method applyConstantPartition.
/*
* If this the first PPTF in the chain and there is no partition specified
* then assume the user wants to include the entire input in 1 partition.
*/
private static void applyConstantPartition(PartitionedTableFunctionSpec spec) {
if (spec.getPartition() != null) {
return;
}
PTFInputSpec iSpec = spec.getInput();
if (iSpec instanceof PTFInputSpec) {
PartitionSpec partSpec = new PartitionSpec();
PartitionExpression partExpr = new PartitionExpression();
partExpr.setExpression(new ASTNode(new CommonToken(HiveParser.Number, "0")));
partSpec.addExpression(partExpr);
spec.setPartition(partSpec);
}
}
use of org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PTFInputSpec in project hive by apache.
the class PTFTranslator method translatePTFChain.
private void translatePTFChain() throws SemanticException {
Deque<PTFInputSpec> ptfChain = new ArrayDeque<PTFInvocationSpec.PTFInputSpec>();
PTFInputSpec currentSpec = ptfInvocation.getFunction();
while (currentSpec != null) {
ptfChain.push(currentSpec);
currentSpec = currentSpec.getInput();
}
int inputNum = 0;
PTFInputDef currentDef = null;
while (!ptfChain.isEmpty()) {
currentSpec = ptfChain.pop();
if (currentSpec instanceof PTFQueryInputSpec) {
currentDef = translate((PTFQueryInputSpec) currentSpec, inputNum);
} else {
currentDef = translate((PartitionedTableFunctionSpec) currentSpec, currentDef, inputNum);
}
inputNum++;
}
ptfDesc.setFuncDef((PartitionedTableFunctionDef) currentDef);
}
use of org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PTFInputSpec in project hive by apache.
the class PTFTranslator method componentize.
public static ArrayList<PTFInvocationSpec> componentize(PTFInvocationSpec ptfInvocation) throws SemanticException {
ArrayList<PTFInvocationSpec> componentInvocations = new ArrayList<PTFInvocationSpec>();
Stack<PTFInputSpec> ptfChain = new Stack<PTFInvocationSpec.PTFInputSpec>();
PTFInputSpec spec = ptfInvocation.getFunction();
while (spec instanceof PartitionedTableFunctionSpec) {
ptfChain.push(spec);
spec = spec.getInput();
}
PartitionedTableFunctionSpec prevFn = (PartitionedTableFunctionSpec) ptfChain.pop();
applyConstantPartition(prevFn);
PartitionSpec partSpec = prevFn.getPartition();
OrderSpec orderSpec = prevFn.getOrder();
if (partSpec == null) {
// oops this should have been caught before trying to componentize
throw new SemanticException("No Partitioning specification specified at start of a PTFChain");
}
if (orderSpec == null) {
orderSpec = new OrderSpec(partSpec);
prevFn.setOrder(orderSpec);
}
while (!ptfChain.isEmpty()) {
PartitionedTableFunctionSpec currentFn = (PartitionedTableFunctionSpec) ptfChain.pop();
String fnName = currentFn.getName();
if (!FunctionRegistry.isTableFunction(fnName)) {
throw new SemanticException(ErrorMsg.INVALID_FUNCTION.getMsg(fnName));
}
boolean transformsRawInput = FunctionRegistry.getTableFunctionResolver(fnName).transformsRawInput();
/*
* if the current table function has no partition info specified: inherit it from the PTF up
* the chain.
*/
if (currentFn.getPartition() == null) {
currentFn.setPartition(prevFn.getPartition());
if (currentFn.getOrder() == null) {
currentFn.setOrder(prevFn.getOrder());
}
}
/*
* If the current table function has no order info specified;
*/
if (currentFn.getOrder() == null) {
currentFn.setOrder(new OrderSpec(currentFn.getPartition()));
}
if (!currentFn.getPartition().equals(partSpec) || !currentFn.getOrder().equals(orderSpec) || transformsRawInput) {
PTFInvocationSpec component = new PTFInvocationSpec();
component.setFunction(prevFn);
componentInvocations.add(component);
PTFQueryInputSpec cQInSpec = new PTFQueryInputSpec();
cQInSpec.setType(PTFQueryInputType.PTFCOMPONENT);
currentFn.setInput(cQInSpec);
}
prevFn = currentFn;
partSpec = prevFn.getPartition();
orderSpec = prevFn.getOrder();
}
componentInvocations.add(ptfInvocation);
return componentInvocations;
}
Aggregations