/** * we already sent a schema to the user, this method checks if the new schema can be converted to match the one already * sent * @param oldSchema schema sent to the user * @param newSchema new schema * @return true if we can convert the schema, false otherwise */ private static boolean isSchemaConvertible(final Map<String, MajorType> oldSchema, final Map<String, MajorType> newSchema) { int numMatchedFields = 0; // for every field of the new schema for (String fieldName : newSchema.keySet()) { final MajorType fieldType = oldSchema.get(fieldName); // check if it's part of the old schema if (fieldType != null) { // if it is confirm if it has the same type if (!fieldType.equals(newSchema.get(fieldName))) { return false; // field has a different type, we cannot convert it } // field has the same type numMatchedFields++; } } // if any of the old schema fields is missing from the schema, we won't be able to convert return oldSchema.size() <= numMatchedFields; }
if (!newType.equals(existingType)) { logger.debug("Column {} is demoted to non-partition column due to type change: existing: {}, new: {}, " + "table {}, file {}, rowgroup index {}",
private static boolean typeEqual(SerializedField field1, SerializedField field2) { if (!field1.getMajorType().equals(field2.getMajorType())) { return false; } if (field1.getChildCount() != field2.getChildCount()) { return false; } for(int i=0; i<field1.getChildCount(); i++) { final SerializedField childField1 = field1.getChild(i); final SerializedField childField2 = field2.getChild(i); if (!typeEqual(childField1, childField2)) { return false; } } return true; }
@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()); }