@Override public Expression visitLeave(IsNullParseNode node, List<Expression> children) throws SQLException { ParseNode childNode = node.getChildren().get(0); Expression child = children.get(0); if (childNode instanceof BindParseNode) { // TODO: valid/possibe? context.getBindManager().addParamMetaData((BindParseNode)childNode, child); } return wrapGroupByExpression(IsNullExpression.create(child, node.isNegate(), context.getTempPtr())); }
@Override public Expression visitLeave(NotParseNode node, List<Expression> children) throws SQLException { ParseNode childNode = node.getChildren().get(0); Expression child = children.get(0); if (!PBoolean.INSTANCE.isCoercibleTo(child.getDataType())) { throw TypeMismatchException.newException(PBoolean.INSTANCE, child.getDataType(), node.toString()); } if (childNode instanceof BindParseNode) { // TODO: valid/possibe? context.getBindManager().addParamMetaData((BindParseNode)childNode, child); } return wrapGroupByExpression(NotExpression.create(child, context.getTempPtr())); }
addBindParamMetaData(lhsNode, rhsNode, lhsExpr, rhsExpr); return wrapGroupByExpression(ComparisonExpression.create(op, children, context.getTempPtr(), context.getCurrentTable().getTable().rowKeyOrderOptimizable()));
keyRangeRhsExpression, result, plan.getContext().getTempPtr())); parent.keyRangeExpressions.add(parent.createKeyRangeExpression(keyRangeLhsExpression, keyRangeRhsExpression, keyRangeRhsValues, plan.getContext().getTempPtr(), plan.getContext().getCurrentTable().getTable().rowKeyOrderOptimizable()));
final ImmutableBytesWritable ptr = context.getTempPtr(); return new SingleKeySlot(new KeyPart() {
@Override public Expression visitLeave(StringConcatParseNode node, List<Expression> children) throws SQLException { final StringConcatExpression expression=new StringConcatExpression(children); for (int i = 0; i < children.size(); i++) { ParseNode childNode=node.getChildren().get(i); if(childNode instanceof BindParseNode) { context.getBindManager().addParamMetaData((BindParseNode)childNode,expression); } PDataType type=children.get(i).getDataType(); if(type == PVarbinary.INSTANCE){ throw new SQLExceptionInfo.Builder(SQLExceptionCode.TYPE_NOT_SUPPORTED_FOR_OPERATOR) .setMessage("Concatenation does not support "+ type +" in expression" + node).build().buildException(); } } ImmutableBytesWritable ptr = context.getTempPtr(); if (ExpressionUtil.isConstant(expression)) { return ExpressionUtil.getConstantExpression(expression, ptr); } return wrapGroupByExpression(expression); }
@Override public Expression visitLeave(InListParseNode node, List<Expression> l) throws SQLException { List<Expression> inChildren = l; Expression firstChild = inChildren.get(0); ImmutableBytesWritable ptr = context.getTempPtr(); PDataType firstChildType = firstChild.getDataType(); ParseNode firstChildNode = node.getChildren().get(0); if (firstChildNode instanceof BindParseNode) { PDatum datum = firstChild; if (firstChildType == null) { datum = inferBindDatum(inChildren); } context.getBindManager().addParamMetaData((BindParseNode)firstChildNode, datum); } for (int i = 1; i < l.size(); i++) { ParseNode childNode = node.getChildren().get(i); if (childNode instanceof BindParseNode) { context.getBindManager().addParamMetaData((BindParseNode)childNode, firstChild); } } return wrapGroupByExpression(InListExpression.create(inChildren, node.isNegate(), ptr, context.getCurrentTable().getTable().rowKeyOrderOptimizable())); }
private Expression visitLeave(ArithmeticParseNode node, List<Expression> children, ArithmeticExpressionBinder binder, ArithmeticExpressionFactory factory) throws SQLException { boolean isNull = false; for (Expression child : children) { boolean isChildLiteral = (child instanceof LiteralExpression); isNull |= isChildLiteral && ((LiteralExpression)child).getValue() == null; } Expression expression = factory.create(node, children); for (int i = 0; i < node.getChildren().size(); i++) { ParseNode childNode = node.getChildren().get(i); if (childNode instanceof BindParseNode) { context.getBindManager().addParamMetaData((BindParseNode)childNode, binder == null ? expression : binder.getBindMetaData(i, children, expression)); } } ImmutableBytesWritable ptr = context.getTempPtr(); // If all children are literals, just evaluate now if (ExpressionUtil.isConstant(expression)) { return ExpressionUtil.getConstantExpression(expression, ptr); } else if (isNull) { return LiteralExpression.newConstant(null, expression.getDataType(), expression.getDeterminism()); } // Otherwise create and return the expression return wrapGroupByExpression(expression); }
private long evalExpression(CreateSequenceStatement sequence, StatementContext context, Expression expression, SQLExceptionCode code) throws SQLException { ImmutableBytesWritable ptr = context.getTempPtr(); expression.evaluate(null, ptr); if (ptr.getLength() == 0 || !expression.getDataType().isCoercibleTo(PLong.INSTANCE)) { TableName sequenceName = sequence.getSequenceName(); throw SequenceUtil.getException(sequenceName.getSchemaName(), sequenceName.getTableName(), code); } return (Long) PLong.INSTANCE.toObject(ptr, expression.getDataType()); }
private ProjectedValueTuple convertLhs(Tuple lhs) throws IOException { ProjectedValueTuple t; if (lhs instanceof ProjectedValueTuple) { t = (ProjectedValueTuple) lhs; } else { ImmutableBytesWritable ptr = getContext().getTempPtr(); TupleProjector.decodeProjectedValue(lhs, ptr); lhsBitSet.clear(); lhsBitSet.or(ptr); int bitSetLen = lhsBitSet.getEstimatedLength(); t = new ProjectedValueTuple(lhs, lhs.getValue(0).getTimestamp(), ptr.get(), ptr.getOffset(), ptr.getLength(), bitSetLen); } return t; } };
private Tuple join(Tuple lhs, Tuple rhs) throws SQLException { try { ProjectedValueTuple t = null; if (lhs == null) { t = new ProjectedValueTuple(rhs, rhs.getValue(0).getTimestamp(), this.emptyProjectedValue, 0, this.emptyProjectedValue.length, this.emptyProjectedValue.length); } else if (lhs instanceof ProjectedValueTuple) { t = (ProjectedValueTuple) lhs; } else { ImmutableBytesWritable ptr = context.getTempPtr(); TupleProjector.decodeProjectedValue(lhs, ptr); lhsBitSet.clear(); lhsBitSet.or(ptr); int bitSetLen = lhsBitSet.getEstimatedLength(); t = new ProjectedValueTuple(lhs, lhs.getValue(0).getTimestamp(), ptr.get(), ptr.getOffset(), ptr.getLength(), bitSetLen); } return rhsBitSet == ValueBitSet.EMPTY_VALUE_BITSET ? t : TupleProjector.mergeProjectedValue( t, joinedSchema, destBitSet, rhs, rhsSchema, rhsBitSet, rhsFieldPosition, true); } catch (IOException e) { throw new SQLException(e); } } }
ImmutableBytesWritable ptr = context.getTempPtr(); RowKeySchema rowKeySchema = table.getRowKeySchema(); int minSpan = rowKeySchema.computeMinSpan(pkPos, result, ptr);
ImmutableBytesWritable ptr = context.getTempPtr(); if (IndexUtil.getViewConstantValue(column, ptr)) { expression = LiteralExpression.newConstant(column.getDataType().toObject(ptr), expression.getDataType());
@Override public Expression visit(ColumnParseNode node) throws SQLException { ColumnRef ref = resolveColumn(node); TableRef tableRef = ref.getTableRef(); ImmutableBytesWritable ptr = context.getTempPtr(); PColumn column = ref.getColumn(); // If we have an UPDATABLE view, then we compile those view constants (i.e. columns in equality constraints // in the view) to constants. This allows the optimize to optimize out reference to them in various scenarios. // If the column is matched in a WHERE clause against a constant not equal to it's constant, then the entire // query would become degenerate. if (!resolveViewConstants && IndexUtil.getViewConstantValue(column, ptr)) { return LiteralExpression.newConstant(column.getDataType().toObject(ptr), column.getDataType()); } if (tableRef.equals(context.getCurrentTable()) && !SchemaUtil.isPKColumn(column)) { // project only kv columns addColumn(column); } Expression expression = ref.newColumnExpression(node.isTableNameCaseSensitive(), node.isCaseSensitive()); Expression wrappedExpression = wrapGroupByExpression(expression); // If we're in an aggregate expression // and we're not in the context of an aggregate function // and we didn't just wrap our column reference // then we're mixing aggregate and non aggregate expressions in the same expression. // This catches cases like this: SELECT sum(a_integer) + a_integer FROM atable GROUP BY a_string if (isAggregate && aggregateFunction == null && wrappedExpression == expression) { throwNonAggExpressionInAggException(expression.toString()); } return wrappedExpression; }
expression = node.create(children, function, context); ImmutableBytesWritable ptr = context.getTempPtr(); BuiltInFunctionInfo info = node.getInfo(); for (int i = 0; i < info.getRequiredArgCount(); i++) {
ExpressionCompiler expressionCompiler = new ExpressionCompiler(context); Expression expression = numToAllocateNode.accept(expressionCompiler); ImmutableBytesWritable ptr = context.getTempPtr(); expression.evaluate(null, ptr); if (ptr.getLength() == 0 || !expression.getDataType().isCoercibleTo(PLong.INSTANCE)) {
@Override public MutationState execute() throws SQLException { ImmutableBytesWritable ptr = context.getTempPtr(); PTable table = tableRef.getTable(); table.getIndexMaintainers(ptr, context.getConnection());
@Override public MutationState execute() throws SQLException { ImmutableBytesWritable ptr = context.getTempPtr(); PTable table = dataPlan.getTableRef().getTable(); table.getIndexMaintainers(ptr, context.getConnection());
private void testCorrelatePlan(Object[][] leftRelation, Object[][] rightRelation, int leftCorrelColumn, int rightCorrelColumn, JoinType type, Object[][] expectedResult, Integer offset) throws SQLException { TableRef leftTable = createProjectedTableFromLiterals(leftRelation[0]); TableRef rightTable = createProjectedTableFromLiterals(rightRelation[0]); String varName = "$cor0"; RuntimeContext runtimeContext = new RuntimeContextImpl(); runtimeContext.defineCorrelateVariable(varName, leftTable); QueryPlan leftPlan = newLiteralResultIterationPlan(leftRelation, offset); QueryPlan rightPlan = newLiteralResultIterationPlan(rightRelation, offset); Expression columnExpr = new ColumnRef(rightTable, rightCorrelColumn).newColumnExpression(); Expression fieldAccess = new CorrelateVariableFieldAccessExpression(runtimeContext, varName, new ColumnRef(leftTable, leftCorrelColumn).newColumnExpression()); Expression filter = ComparisonExpression.create(CompareOp.EQUAL, Arrays.asList(columnExpr, fieldAccess), CONTEXT.getTempPtr(), false); rightPlan = new ClientScanPlan(CONTEXT, SelectStatement.SELECT_ONE, rightTable, RowProjector.EMPTY_PROJECTOR, null, null, filter, OrderBy.EMPTY_ORDER_BY, rightPlan); PTable joinedTable = JoinCompiler.joinProjectedTables(leftTable.getTable(), rightTable.getTable(), type); CorrelatePlan correlatePlan = new CorrelatePlan(leftPlan, rightPlan, varName, type, false, runtimeContext, joinedTable, leftTable.getTable(), rightTable.getTable(), leftTable.getTable().getColumns().size()); ResultIterator iter = correlatePlan.iterator(); ImmutableBytesWritable ptr = new ImmutableBytesWritable(); for (Object[] row : expectedResult) { Tuple next = iter.next(); assertNotNull(next); for (int i = 0; i < row.length; i++) { PColumn column = joinedTable.getColumns().get(i); boolean eval = new ProjectedColumnExpression(column, joinedTable, column.getName().getString()).evaluate(next, ptr); Object o = eval ? column.getDataType().toObject(ptr) : null; assertEquals(row[i], o); } } }
PDataType targetType = this.getDataType(); context.getTempPtr().set(ptr.get(), ptr.getOffset(), ptr.getLength()); try { targetType.coerceBytes(context.getTempPtr(), defaultValue.getValue(), sourceType, defaultValue.getMaxLength(), defaultValue.getScale(), defaultValue.getSortOrder(),