@SuppressWarnings("unchecked") @Override public <T extends ValueVector> AddOrGetResult<T> addOrGetVector(VectorDescriptor descriptor) { boolean created = false; if (vector == DEFAULT_DATA_VECTOR && descriptor.getType().getMinorType() != TypeProtos.MinorType.LATE) { final MaterializedField field = descriptor.withName(DATA_VECTOR_NAME).getField(); vector = BasicTypeHelper.getNewVector(field, allocator); // returned vector must have the same field assert field.equals(vector.getField()); getField().addChild(field); created = true; } final TypeProtos.MajorType actual = vector.getField().getType(); if (!actual.equals(descriptor.getType())) { final String msg = String.format("Inner vector type mismatch. Requested type: [%s], actual type: [%s]", descriptor.getType(), actual); throw new SchemaChangeRuntimeException(msg); } return new AddOrGetResult<>((T)vector, created); }
/** * Method to replace existing list of vectors with the newly provided ValueVectors list in this HyperVectorWrapper * @param vv - New list of ValueVectors to be stored */ @SuppressWarnings("unchecked") public void updateVectorList(ValueVector[] vv) { Preconditions.checkArgument(vv.length > 0); Preconditions.checkArgument(getField().getType().equals(vv[0].getField().getType())); // vectors.length will always be > 0 since in constructor that is enforced Preconditions.checkArgument(vv[0].getClass().equals(vectors[0].getClass())); clear(); final Class<?> clazz = vv[0].getClass(); final ValueVector[] c = (ValueVector[]) Array.newInstance(clazz, vv.length); System.arraycopy(vv, 0, c, 0, vv.length); vectors = (T[])c; } }
return false; if (!ParquetReaderUtility.getType(primitiveType, originalType, scale, precision).equals(partitionColTypeMap.get(schemaPath))) { partitionColTypeMap.remove(schemaPath); return false;
if (! currentChild.getType().equals(newChild.getMajorType())) { return false;
if (v == null || !v.getField().getType().equals(field.getType())) {
true); if (UNKNOWN_TYPE.equals(returnType)) { return nullableAnyType;
/** * This method should be called with MaterializedField which also has correct children field list specially when * the field type is MAP. Otherwise after calling this method if caller is not creating TransferPair on the * ValueVector, then the new ValueVector will not have information about it's list of children MaterializedField. * @param field * @param callBack * @param <T> * @return */ @SuppressWarnings("unchecked") public <T extends ValueVector> T addOrGet(final MaterializedField field, final SchemaChangeCallBack callBack) { final TypedFieldId id = getValueVectorId(SchemaPath.getSimplePath(field.getName())); final ValueVector vector; if (id != null) { vector = getValueAccessorById(id.getFieldIds()).getValueVector(); if (id.getFieldIds().length == 1 && !vector.getField().getType().equals(field.getType())) { final ValueVector newVector = TypeHelper.getNewVector(field, this.getAllocator(), callBack); replace(vector, newVector); return (T) newVector; } } else { vector = TypeHelper.getNewVector(field, this.getAllocator(), callBack); add(vector); } return (T) vector; }
/** * We treat fields with same set of Subtypes as equal, even if they are in a different order * @param t1 * @param t2 * @return */ private boolean majorTypeEqual(MajorType t1, MajorType t2) { if (t1.equals(t2)) { return true; } if (!t1.getMinorType().equals(t2.getMinorType())) { return false; } if (!t1.getMode().equals(t2.getMode())) { return false; } if (!Sets.newHashSet(t1.getSubTypeList()).equals(Sets.newHashSet(t2.getSubTypeList()))) { return false; } return true; }
@SuppressWarnings("unchecked") @Override public <T extends ValueVector> AddOrGetResult<T> addOrGetVector(VectorDescriptor descriptor) { boolean created = false; if (vector == DEFAULT_DATA_VECTOR && descriptor.getType().getMinorType() != TypeProtos.MinorType.LATE) { final MaterializedField field = descriptor.withName(DATA_VECTOR_NAME).getField(); vector = BasicTypeHelper.getNewVector(field, allocator); // returned vector must have the same field assert field.equals(vector.getField()); getField().addChild(field); created = true; } final TypeProtos.MajorType actual = vector.getField().getType(); if (!actual.equals(descriptor.getType())) { final String msg = String.format("Inner vector type mismatch. Requested type: [%s], actual type: [%s]", descriptor.getType(), actual); throw new SchemaChangeRuntimeException(msg); } return new AddOrGetResult<>((T)vector, created); }
/** * Transfer vectors to destination HyperVectorWrapper. * Both this and destination must be of same type and have same number of vectors. * @param destination destination HyperVectorWrapper. */ @Override public void transfer(VectorWrapper<?> destination) { Preconditions.checkArgument(destination instanceof HyperVectorWrapper); Preconditions.checkArgument(getField().getType().equals(destination.getField().getType())); Preconditions.checkArgument(vectors.length == ((HyperVectorWrapper<?>)destination).vectors.length); final ValueVector[] destionationVectors = ((HyperVectorWrapper<?>)destination).vectors; for (int i = 0; i < vectors.length; ++i) { vectors[i].makeTransferPair(destionationVectors[i]).transfer(); } }
@SuppressWarnings("unchecked") @Override public Statistics<T> visitTypedFieldExpr(TypedFieldExpr typedFieldExpr, Void value) throws RuntimeException { final ColumnStatistics<T> columnStatistics = columnStatMap.get(typedFieldExpr.getPath()); if (columnStatistics != null) { return columnStatistics.getStatistics(); } else if (typedFieldExpr.getMajorType().equals(Types.OPTIONAL_INT)) { // field does not exist. Statistics<T> statistics = Statistics.getStatsBasedOnType(PrimitiveType.PrimitiveTypeName.INT32); statistics.setNumNulls(rowCount); // all values are nulls return statistics; } return null; }
@Override public Boolean visitDecimal38Constant(Decimal38Expression decExpr, LogicalExpression value) throws RuntimeException { if (!(value instanceof Decimal38Expression)) { return false; } if (decExpr.getBigDecimal() != ((Decimal38Expression) value).getBigDecimal()) { return false; } if (!decExpr.getMajorType().equals(((Decimal38Expression) value).getMajorType())) { return false; } return true; }
private boolean checkType(LogicalExpression e1, LogicalExpression e2) { return e1.getMajorType().equals(e2.getMajorType()); } }
@Override public Boolean visitVarDecimalConstant(VarDecimalExpression decExpr, LogicalExpression value) throws RuntimeException { if (!(value instanceof VarDecimalExpression)) { return false; } if (!decExpr.getMajorType().equals(value.getMajorType())) { return false; } if (!decExpr.getBigDecimal().equals(((VarDecimalExpression) value).getBigDecimal())) { return false; } return true; }
@Override public Boolean visitNullExpression(NullExpression e, LogicalExpression value) throws RuntimeException { if (!(value instanceof NullExpression)) { return false; } return e.getMajorType().equals(value.getMajorType()); }
@Override public RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call) { if (NONE.equals(returnType)) { return validator.getTypeFactory().createSqlType(SqlTypeName.ANY); } /* * We return a nullable output type both in validation phase and in * Sql to Rel phase. We don't know the type of the output until runtime * hence have to choose the least restrictive type to avoid any wrong * results. */ return getNullableReturnDataType(validator.getTypeFactory()); }
@Override public Boolean visitCastExpression(CastExpression e, LogicalExpression value) throws RuntimeException { if (!(value instanceof CastExpression)) { return false; } if (!e.getMajorType().equals(value.getMajorType())) { return false; } return checkChildren(e, value); }
@Override public Boolean visitNullConstant(TypedNullConstant e, LogicalExpression value) throws RuntimeException { if (!(value instanceof TypedNullConstant)) { return false; } return value.getMajorType().equals(e.getMajorType()); }
@Override public void transfer(VectorWrapper<?> destination) { Preconditions.checkArgument(destination instanceof SimpleVectorWrapper); Preconditions.checkArgument(getField().getType().equals(destination.getField().getType())); vector.makeTransferPair(((SimpleVectorWrapper<?>)destination).vector).transfer(); }