private void init(List<Expression> children) { this.children = ImmutableList.copyOf(children); boolean isStateless = true; boolean isNullable = false; boolean requiresFinalEvaluation = false; boolean cloneExpression = false; this.determinism = Determinism.ALWAYS; for (int i = 0; i < children.size(); i++) { Expression child = children.get(i); isNullable |= child.isNullable(); isStateless &= child.isStateless(); this.determinism = this.determinism.combine(child.getDeterminism()); requiresFinalEvaluation |= child.requiresFinalEvaluation(); cloneExpression |= child.isCloneExpression(); } this.isStateless = isStateless; this.isNullable = isNullable; this.requiresFinalEvaluation = requiresFinalEvaluation; this.cloneExpression = cloneExpression; }
private static LiteralExpression getNullLiteralExpression(Determinism determinism) { return NULL_EXPRESSIONS[determinism.ordinal()] ; }
@Override public void readFields(DataInput input) throws IOException { int encodedByteLengthAndBool = WritableUtils.readVInt(input); int byteLength = Math.abs(encodedByteLengthAndBool)-1; this.byteValue = new byte[byteLength]; input.readFully(byteValue, 0, byteLength); int sortOrderAndDeterminism = WritableUtils.readVInt(input); if (sortOrderAndDeterminism<=2) { //client is on an older version this.determinism = encodedByteLengthAndBool > 0 ? Determinism.ALWAYS : Determinism.PER_ROW; this.sortOrder = SortOrder.fromSystemValue(sortOrderAndDeterminism);; } else { int determinismOrdinal = (sortOrderAndDeterminism>>2)-1; this.determinism = Determinism.values()[determinismOrdinal]; int sortOrderValue = sortOrderAndDeterminism & ((1 << 2) - 1); //get the least 2 significant bits this.sortOrder = SortOrder.fromSystemValue(sortOrderValue); } int typeOrdinal = WritableUtils.readVInt(input); if (typeOrdinal < 0) { this.type = null; } else { this.type = PDataType.values()[typeOrdinal]; } if (this.byteValue.length == 0) { this.value = null; } else { this.value = this.type.toObject(byteValue, 0, byteValue.length, this.type, sortOrder); } }
@Override public boolean isCloneNode(Expression node, List<Expression> children) { return Determinism.PER_INVOCATION.compareTo(node.getDeterminism()) <= 0; } }
public static boolean isFalse(Expression child) { if (child!=null) { return child == BOOLEAN_EXPRESSIONS[child.getDeterminism().ordinal()]; } return false; }
@Override public void readFields(DataInput input) throws IOException { int encodedByteLengthAndBool = WritableUtils.readVInt(input); int byteLength = Math.abs(encodedByteLengthAndBool)-1; this.byteValue = new byte[byteLength]; input.readFully(byteValue, 0, byteLength); int sortOrderAndDeterminism = WritableUtils.readVInt(input); if (sortOrderAndDeterminism<=2) { //client is on an older version this.determinism = encodedByteLengthAndBool > 0 ? Determinism.ALWAYS : Determinism.PER_ROW; this.sortOrder = SortOrder.fromSystemValue(sortOrderAndDeterminism);; } else { int determinismOrdinal = (sortOrderAndDeterminism>>2)-1; this.determinism = Determinism.values()[determinismOrdinal]; int sortOrderValue = sortOrderAndDeterminism & ((1 << 2) - 1); //get the least 2 significant bits this.sortOrder = SortOrder.fromSystemValue(sortOrderValue); } int typeOrdinal = WritableUtils.readVInt(input); if (typeOrdinal < 0) { this.type = null; } else { this.type = PDataType.values()[typeOrdinal]; } if (this.byteValue.length == 0) { this.value = null; } else { this.value = this.type.toObject(byteValue, 0, byteValue.length, this.type, sortOrder); } }
@Override public boolean isCloneNode(Expression node, List<Expression> children) { return Determinism.PER_INVOCATION.compareTo(node.getDeterminism()) <= 0; } }
private Expression orExpression(List<Expression> children) throws SQLException { Iterator<Expression> iterator = children.iterator(); Determinism determinism = Determinism.ALWAYS; while (iterator.hasNext()) { Expression child = iterator.next(); if (child.getDataType() != PBoolean.INSTANCE) { throw TypeMismatchException.newException(PBoolean.INSTANCE, child.getDataType(), child.toString()); } if (LiteralExpression.isFalse(child)) { iterator.remove(); } if (LiteralExpression.isTrue(child)) { return child; } determinism = determinism.combine(child.getDeterminism()); } if (children.size() == 0) { return LiteralExpression.newConstant(false, determinism); } if (children.size() == 1) { return children.get(0); } return new OrExpression(children); }
@Override public void readFields(DataInput input) throws IOException { int encodedByteLengthAndBool = WritableUtils.readVInt(input); int byteLength = Math.abs(encodedByteLengthAndBool)-1; this.byteValue = new byte[byteLength]; input.readFully(byteValue, 0, byteLength); int sortOrderAndDeterminism = WritableUtils.readVInt(input); if (sortOrderAndDeterminism<=2) { //client is on an older version this.determinism = encodedByteLengthAndBool > 0 ? Determinism.ALWAYS : Determinism.PER_ROW; this.sortOrder = SortOrder.fromSystemValue(sortOrderAndDeterminism);; } else { int determinismOrdinal = (sortOrderAndDeterminism>>2)-1; this.determinism = Determinism.values()[determinismOrdinal]; int sortOrderValue = sortOrderAndDeterminism & ((1 << 2) - 1); //get the least 2 significant bits this.sortOrder = SortOrder.fromSystemValue(sortOrderValue); } int typeOrdinal = WritableUtils.readVInt(input); if (typeOrdinal < 0) { this.type = null; } else { this.type = PDataType.values()[typeOrdinal]; } if (this.byteValue.length == 0) { this.value = null; } else { this.value = this.type.toObject(byteValue, 0, byteValue.length, this.type, sortOrder); } }
public static Expression create(List<Expression> children) throws SQLException { Determinism determinism = Determinism.ALWAYS; Iterator<Expression> iterator = children.iterator(); while (iterator.hasNext()) { Expression child = iterator.next(); if (child.getDataType() != PBoolean.INSTANCE) { throw TypeMismatchException.newException(PBoolean.INSTANCE, child.getDataType(), child.toString()); } if (LiteralExpression.isFalse(child)) { return child; } if (LiteralExpression.isTrue(child)) { iterator.remove(); } determinism.combine(child.getDeterminism()); } if (children.size() == 0) { return LiteralExpression.newConstant(true, determinism); } if (children.size() == 1) { return children.get(0); } return new AndExpression(children); }
private static LiteralExpression getTypedNullLiteralExpression(PDataType type, Determinism determinism){ return TYPED_NULL_EXPRESSIONS[type.ordinal()+PDataType.values().length*determinism.ordinal()]; }
@Test public void testCombine() { // combining a determinism enum with ALWAYS should always return the // other determinism assertEquals("Unexpected result ", Determinism.PER_ROW, Determinism.ALWAYS.combine(Determinism.PER_ROW)); assertEquals("Unexpected result ", Determinism.PER_STATEMENT, Determinism.ALWAYS.combine(Determinism.PER_STATEMENT)); assertEquals("Unexpected result ", Determinism.PER_STATEMENT, Determinism.PER_STATEMENT.combine(Determinism.ALWAYS)); assertEquals("Unexpected result ", Determinism.PER_ROW, Determinism.PER_ROW.combine(Determinism.ALWAYS)); // combining PER_STATEMENT and PER_ROW should return PER_ROW assertEquals("Unexpected result ", Determinism.PER_ROW, Determinism.PER_STATEMENT.combine(Determinism.PER_ROW)); assertEquals("Unexpected result ", Determinism.PER_ROW, Determinism.PER_ROW.combine(Determinism.PER_STATEMENT)); } }
public static boolean isBooleanNull(Expression child) { if (child!=null) { return child == TYPED_NULL_EXPRESSIONS[PBoolean.INSTANCE.ordinal()+PDataType.values().length*child.getDeterminism().ordinal()]; } return false; }
for(int i = 0; i < children.size(); i++) { Expression e = children.get(i); determinism = determinism.combine(e.getDeterminism()); PDataType type = e.getDataType(); if (type == null) {