private <T> TypeComparator<T> getTypeComparator(ExecutionConfig executionConfig, TypeInformation<T> inputType, int[] inputKeys, boolean[] inputSortDirections) { if (!(inputType instanceof CompositeType)) { throw new InvalidProgramException("Input types of coGroup must be composite types."); } return ((CompositeType<T>) inputType).createComparator(inputKeys, inputSortDirections, 0, executionConfig); }
private static <T> String getSerializerTree(TypeInformation<T> ti, int indent) { String ret = ""; if (ti instanceof CompositeType) { ret += StringUtils.repeat(' ', indent) + ti.getClass().getSimpleName() + "\n"; CompositeType<T> cti = (CompositeType<T>) ti; String[] fieldNames = cti.getFieldNames(); for (int i = 0; i < cti.getArity(); i++) { TypeInformation<?> fieldType = cti.getTypeAt(i); ret += StringUtils.repeat(' ', indent + 2) + fieldNames[i] + ":" + getSerializerTree(fieldType, indent); } } else { if (ti instanceof GenericTypeInfo) { ret += StringUtils.repeat(' ', indent) + "GenericTypeInfo (" + ti.getTypeClass().getSimpleName() + ")\n"; ret += getGenericTypeTree(ti.getTypeClass(), indent + 4); } else { ret += StringUtils.repeat(' ', indent) + ti.toString() + "\n"; } } return ret; }
String[] fieldNames = cType.getFieldNames(); this.originalKeyTypes = new TypeInformation<?>[keyPositions.length]; ArrayList<FlatFieldDescriptor> tmpList = new ArrayList<>(); tmpList.clear(); this.originalKeyTypes[i] = cType.getTypeAt(keyPos); cType.getFlatFields(fieldNames[keyPos], 0, tmpList);
/** * Returns all GenericTypeInfos contained in a composite type. * * @param typeInfo {@link CompositeType} */ private static void getContainedGenericTypes(CompositeType<?> typeInfo, List<GenericTypeInfo<?>> target) { for (int i = 0; i < typeInfo.getArity(); i++) { TypeInformation<?> type = typeInfo.getTypeAt(i); if (type instanceof CompositeType) { getContainedGenericTypes((CompositeType<?>) type, target); } else if (type instanceof GenericTypeInfo) { if (!target.contains(type)) { target.add((GenericTypeInfo<?>) type); } } } }
/** * Creates a table schema from a {@link TypeInformation} instance. If the type information is * a {@link CompositeType}, the field names and types for the composite type are used to * construct the {@link TableSchema} instance. Otherwise, a table schema with a single field * is created. The field name is "f0" and the field type the provided type. * * @param typeInfo The {@link TypeInformation} from which the table schema is generated. * @return The table schema that was generated from the given {@link TypeInformation}. */ public static TableSchema fromTypeInfo(TypeInformation<?> typeInfo) { if (typeInfo instanceof CompositeType<?>) { final CompositeType<?> compositeType = (CompositeType<?>) typeInfo; // get field names and types from composite type final String[] fieldNames = compositeType.getFieldNames(); final TypeInformation<?>[] fieldTypes = new TypeInformation[fieldNames.length]; for (int i = 0; i < fieldTypes.length; i++) { fieldTypes[i] = compositeType.getTypeAt(i); } return new TableSchema(fieldNames, fieldTypes); } else { // create table schema with a single field named "f0" of the given type. return new TableSchema( new String[]{ATOMIC_TYPE_FIELD_NAME}, new TypeInformation<?>[]{typeInfo}); } }
public TypeComparator<T> createComparator(int[] logicalKeyFields, boolean[] orders, int logicalFieldOffset, ExecutionConfig config) { TypeComparatorBuilder<T> builder = createTypeComparatorBuilder(); boolean comparatorAdded = false; for (int localFieldId = 0; localFieldId < this.getArity() && logicalField <= logicalKeyField && !comparatorAdded; localFieldId++) { TypeInformation<?> localFieldType = this.getTypeAt(localFieldId); ((CompositeType<?>) localFieldType).createComparator( new int[]{logicalKeyField}, new boolean[]{orders[logicalKeyFieldIndex]},
private static TypeInformation<?> getExpressionTypeInformation(String fieldStr, TypeInformation<?> typeInfo) { Matcher wildcardMatcher = PATTERN_WILDCARD.matcher(fieldStr); if (wildcardMatcher.matches()) { return typeInfo; } else { Matcher expMatcher = PATTERN_FIELD.matcher(fieldStr); if (!expMatcher.matches()) { throw new InvalidFieldReferenceException("Invalid field expression \"" + fieldStr + "\"."); } if (typeInfo instanceof CompositeType<?>) { return ((CompositeType<?>) typeInfo).getTypeAt(expMatcher.group(1)); } else { throw new InvalidFieldReferenceException("Nested field expression \"" + fieldStr + "\" not possible on atomic type (" + typeInfo + ")."); } } }
List<FlatFieldDescriptor> flatFields = cType.getFlatFields(keyExpr); this.originalKeyTypes[i] = type; } else { this.originalKeyTypes[i] = cType.getTypeAt(strippedKeyExpr);
if (fType instanceof CompositeType) { CompositeType<?> cType = (CompositeType<?>) fType; cType.getFlatFields(ExpressionKeys.SELECT_ALL_CHAR, offset + keyPosition, result); keyPosition += cType.getTotalFields() - 1; } else { result.add(new FlatFieldDescriptor(offset + keyPosition, fType)); ((CompositeType) fieldType).getFlatFields("*", offset, result); } else { result.add(new FlatFieldDescriptor(offset, fieldType)); ((CompositeType) fieldType).getFlatFields(tail, offset, result); } else { throw new InvalidFieldReferenceException(
/** * Returns the flat field descriptors for the given field expression. * * @param fieldExpression The field expression for which the flat field descriptors are computed. * @return The list of descriptors for the flat fields which are specified by the field expression. */ @PublicEvolving public List<FlatFieldDescriptor> getFlatFields(String fieldExpression) { List<FlatFieldDescriptor> result = new ArrayList<FlatFieldDescriptor>(); this.getFlatFields(fieldExpression, 0, result); return result; }
@Override public boolean equals(Object obj) { if (obj instanceof CompositeType) { @SuppressWarnings("unchecked") CompositeType<T> compositeType = (CompositeType<T>)obj; return compositeType.canEqual(this) && typeClass == compositeType.typeClass; } else { return false; } }
public TypeComparator<T> createComparator(int[] logicalKeyFields, boolean[] orders, int logicalFieldOffset, ExecutionConfig config) { TypeComparatorBuilder<T> builder = createTypeComparatorBuilder(); boolean comparatorAdded = false; for (int localFieldId = 0; localFieldId < this.getArity() && logicalField <= logicalKeyField && !comparatorAdded; localFieldId++) { TypeInformation<?> localFieldType = this.getTypeAt(localFieldId); ((CompositeType<?>) localFieldType).createComparator( new int[]{logicalKeyField}, new boolean[]{orders[logicalKeyFieldIndex]},
public static boolean isSortKey(String fieldExpr, TypeInformation<?> type) { TypeInformation<?> sortKeyType; fieldExpr = fieldExpr.trim(); if (SELECT_ALL_CHAR.equals(fieldExpr) || SELECT_ALL_CHAR_SCALA.equals(fieldExpr)) { sortKeyType = type; } else { if (type instanceof CompositeType) { sortKeyType = ((CompositeType<?>) type).getTypeAt(fieldExpr); } else { throw new InvalidProgramException( "Field expression must be equal to '" + SELECT_ALL_CHAR + "' or '" + SELECT_ALL_CHAR_SCALA + "' for atomic types."); } } return sortKeyType.isSortKeyType(); }
/** * Creates a table schema from a {@link TypeInformation} instance. If the type information is * a {@link CompositeType}, the field names and types for the composite type are used to * construct the {@link TableSchema} instance. Otherwise, a table schema with a single field * is created. The field name is "f0" and the field type the provided type. * * @param typeInfo The {@link TypeInformation} from which the table schema is generated. * @return The table schema that was generated from the given {@link TypeInformation}. */ public static TableSchema fromTypeInfo(TypeInformation<?> typeInfo) { if (typeInfo instanceof CompositeType<?>) { final CompositeType<?> compositeType = (CompositeType<?>) typeInfo; // get field names and types from composite type final String[] fieldNames = compositeType.getFieldNames(); final TypeInformation<?>[] fieldTypes = new TypeInformation[fieldNames.length]; for (int i = 0; i < fieldTypes.length; i++) { fieldTypes[i] = compositeType.getTypeAt(i); } return new TableSchema(fieldNames, fieldTypes); } else { // create table schema with a single field named "f0" of the given type. return new TableSchema( new String[]{ATOMIC_TYPE_FIELD_NAME}, new TypeInformation<?>[]{typeInfo}); } }
List<FlatFieldDescriptor> flatFields = cType.getFlatFields(keyExpr); this.originalKeyTypes[i] = type; } else { this.originalKeyTypes[i] = cType.getTypeAt(strippedKeyExpr);
if (type instanceof CompositeType) { CompositeType<?> cType = (CompositeType<?>) type; cType.getFlatFields(String.valueOf(ExpressionKeys.SELECT_ALL_CHAR), offset + keyPosition, result); keyPosition += cType.getTotalFields() - 1; } else { result.add(new FlatFieldDescriptor(offset + keyPosition, type)); ((CompositeType<?>) fieldType).getFlatFields("*", offset, result); } else { offset += this.getTypeAt(i).getTotalFields(); ((CompositeType<?>) fieldType).getFlatFields(tail, offset, result); } else { throw new InvalidFieldReferenceException("Nested field expression \"" + tail + "\" not possible on atomic type " + fieldType + ".");
private static List<FlatFieldDescriptor> getFlatFields(String fieldStr, TypeInformation<?> typeInfo) { if (typeInfo instanceof CompositeType<?>) { return ((CompositeType<?>) typeInfo).getFlatFields(fieldStr); } else { Matcher wildcardMatcher = PATTERN_WILDCARD.matcher(fieldStr); if (wildcardMatcher.matches()) { return Collections.singletonList(new FlatFieldDescriptor(0, typeInfo)); } else { throw new InvalidFieldReferenceException("Nested field expression \"" + fieldStr + "\" not possible on atomic type (" + typeInfo + ")."); } } }
@Override public boolean equals(Object obj) { if (obj instanceof CompositeType) { @SuppressWarnings("unchecked") CompositeType<T> compositeType = (CompositeType<T>)obj; return compositeType.canEqual(this) && typeClass == compositeType.typeClass; } else { return false; } }
@SuppressWarnings("unchecked") private <T> TypeComparator<T> buildComparatorFor(int input, ExecutionConfig executionConfig, TypeInformation<T> typeInformation) { TypeComparator<T> comparator; if (typeInformation instanceof AtomicType) { comparator = ((AtomicType<T>) typeInformation).createComparator(true, executionConfig); } else if (typeInformation instanceof CompositeType) { int[] keyPositions = getKeyColumns(input); boolean[] orders = new boolean[keyPositions.length]; Arrays.fill(orders, true); comparator = ((CompositeType<T>) typeInformation).createComparator(keyPositions, orders, 0, executionConfig); } else { throw new RuntimeException("Type information for input of type " + typeInformation.getClass() .getCanonicalName() + " is not supported. Could not generate a comparator."); } return comparator; }