use of org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionExpression in project hive by apache.
the class PTFTranslator method translate.
private PartitionDef translate(ShapeDetails inpShape, PartitionSpec spec) throws SemanticException {
if (spec == null || spec.getExpressions() == null || spec.getExpressions().size() == 0) {
return null;
}
PartitionDef pDef = new PartitionDef();
for (PartitionExpression pExpr : spec.getExpressions()) {
PTFExpressionDef expDef = translate(inpShape, pExpr);
pDef.addExpression(expDef);
}
return pDef;
}
use of org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionExpression in project hive by apache.
the class WindowingSpec method applyConstantPartition.
private void applyConstantPartition(WindowSpec wdwSpec) {
PartitionSpec partSpec = wdwSpec.getPartition();
if (partSpec == null) {
partSpec = new PartitionSpec();
PartitionExpression partExpr = new PartitionExpression();
partExpr.setExpression(new ASTNode(new CommonToken(HiveParser.Number, "0")));
partSpec.addExpression(partExpr);
wdwSpec.setPartition(partSpec);
}
}
use of org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionExpression in project hive by apache.
the class SemanticAnalyzer method genReduceSinkPlanForWindowing.
private Operator genReduceSinkPlanForWindowing(WindowingSpec spec, RowResolver inputRR, Operator input) throws SemanticException {
ArrayList<ExprNodeDesc> partCols = new ArrayList<ExprNodeDesc>();
ArrayList<ExprNodeDesc> orderCols = new ArrayList<ExprNodeDesc>();
StringBuilder order = new StringBuilder();
StringBuilder nullOrder = new StringBuilder();
for (PartitionExpression partCol : spec.getQueryPartitionSpec().getExpressions()) {
ExprNodeDesc partExpr = genExprNodeDesc(partCol.getExpression(), inputRR);
if (ExprNodeDescUtils.indexOf(partExpr, partCols) < 0) {
partCols.add(partExpr);
orderCols.add(partExpr);
order.append('+');
nullOrder.append('a');
}
}
if (spec.getQueryOrderSpec() != null) {
for (OrderExpression orderCol : spec.getQueryOrderSpec().getExpressions()) {
ExprNodeDesc orderExpr = genExprNodeDesc(orderCol.getExpression(), inputRR);
char orderChar = orderCol.getOrder() == PTFInvocationSpec.Order.ASC ? '+' : '-';
char nullOrderChar = orderCol.getNullOrder() == PTFInvocationSpec.NullOrder.NULLS_FIRST ? 'a' : 'z';
int index = ExprNodeDescUtils.indexOf(orderExpr, orderCols);
if (index >= 0) {
order.setCharAt(index, orderChar);
nullOrder.setCharAt(index, nullOrderChar);
continue;
}
orderCols.add(genExprNodeDesc(orderCol.getExpression(), inputRR));
order.append(orderChar);
nullOrder.append(nullOrderChar);
}
}
return genReduceSinkPlan(input, partCols, orderCols, order.toString(), nullOrder.toString(), -1, Operation.NOT_ACID);
}
use of org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionExpression in project hive by apache.
the class PTFTranslator method addPartitionExpressionsToOrderList.
protected static ArrayList<OrderExpression> addPartitionExpressionsToOrderList(ArrayList<PartitionExpression> partCols, ArrayList<OrderExpression> orderCols) throws SemanticException {
int numOfPartColumns = 0;
int chkSize = partCols.size();
chkSize = chkSize > orderCols.size() ? orderCols.size() : chkSize;
for (int i = 0; i < chkSize; i++) {
if (orderCols.get(i).getExpression().toStringTree().equals(partCols.get(i).getExpression().toStringTree())) {
numOfPartColumns++;
} else {
break;
}
}
if (numOfPartColumns != 0 && numOfPartColumns != partCols.size()) {
List<String> partitionColumnNames = new ArrayList<String>();
for (PartitionExpression partitionExpression : partCols) {
ASTNode column = partitionExpression.getExpression();
if (column != null && column.getChildCount() > 0) {
partitionColumnNames.add(column.getChild(0).getText());
}
}
throw new SemanticException(String.format("all partition columns %s must be in order clause or none should be specified", partitionColumnNames.toString()));
}
ArrayList<OrderExpression> combinedOrdExprs = new ArrayList<OrderExpression>();
if (numOfPartColumns == 0) {
for (PartitionExpression partCol : partCols) {
OrderExpression orderCol = new OrderExpression(partCol);
combinedOrdExprs.add(orderCol);
}
}
combinedOrdExprs.addAll(orderCols);
return combinedOrdExprs;
}
use of org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionExpression 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);
}
}
Aggregations