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 + ")."); } } }
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(); }
/** * 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); } } } }
@Override @PublicEvolving public boolean isKeyType() { for(int i=0;i<this.getArity();i++) { if (!this.getTypeAt(i).isKeyType()) { return false; } } return true; }
@Override @PublicEvolving public boolean isSortKeyType() { for(int i=0;i<this.getArity();i++) { if (!this.getTypeAt(i).isSortKeyType()) { return false; } } return true; }
} else { if (fieldType instanceof CompositeType) { return ((CompositeType<?>) fieldType).getTypeAt(tail); } else { throw new InvalidFieldReferenceException(
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; }
} else { if(fieldType instanceof CompositeType<?>) { return ((CompositeType<?>) fieldType).getTypeAt(tail); } else { throw new InvalidFieldReferenceException("Nested field expression \""+tail+"\" not possible on atomic type "+fieldType+".");
public static SingleInputSemanticProperties createProjectionPropertiesSingle(int[] fields, CompositeType<?> inType) { Character.isJavaIdentifierStart(1); SingleInputSemanticProperties ssp = new SingleInputSemanticProperties(); int[] sourceOffsets = new int[inType.getArity()]; sourceOffsets[0] = 0; for (int i = 1; i < inType.getArity(); i++) { sourceOffsets[i] = inType.getTypeAt(i - 1).getTotalFields() + sourceOffsets[i - 1]; } int targetOffset = 0; for (int i = 0; i < fields.length; i++) { int sourceOffset = sourceOffsets[fields[i]]; int numFieldsToCopy = inType.getTypeAt(fields[i]).getTotalFields(); for (int j = 0; j < numFieldsToCopy; j++) { ssp.addForwardedField(sourceOffset + j, targetOffset + j); } targetOffset += numFieldsToCopy; } return ssp; }
} else { if(fieldType instanceof CompositeType<?>) { return ((CompositeType<?>) fieldType).getTypeAt(tail); } else { throw new InvalidFieldReferenceException("Nested field expression \""+tail+"\" not possible on atomic type "+fieldType+".");
/** * 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 static boolean isSortKey(int fieldPos, TypeInformation<?> type) { if (!type.isTupleType() || !(type instanceof CompositeType)) { throw new InvalidProgramException("Specifying keys via field positions is only valid " + "for tuple data types. Type: " + type); } if (type.getArity() == 0) { throw new InvalidProgramException("Tuple size must be greater than 0. Size: " + type.getArity()); } if(fieldPos < 0 || fieldPos >= type.getArity()) { throw new IndexOutOfBoundsException("Tuple position is out of range: " + fieldPos); } TypeInformation<?> sortKeyType = ((CompositeType<?>)type).getTypeAt(fieldPos); return sortKeyType.isSortKeyType(); }
this.originalKeyTypes[i] = type; } else { this.originalKeyTypes[i] = cType.getTypeAt(strippedKeyExpr);
tmpList.clear(); this.originalKeyTypes[i] = cType.getTypeAt(keyPos); cType.getFlatFields(fieldNames[keyPos], 0, tmpList);
TypeInformation<?> localFieldType = this.getTypeAt(localFieldId);
@Override @PublicEvolving public boolean isSortKeyType() { for(int i=0;i<this.getArity();i++) { if (!this.getTypeAt(i).isSortKeyType()) { return false; } } return true; }
@Override @PublicEvolving public boolean isKeyType() { for(int i=0;i<this.getArity();i++) { if (!this.getTypeAt(i).isKeyType()) { return false; } } return true; }
@Override @PublicEvolving public boolean isKeyType() { for(int i=0;i<this.getArity();i++) { if (!this.getTypeAt(i).isKeyType()) { return false; } } return true; }
@Override @PublicEvolving public boolean isSortKeyType() { for(int i=0;i<this.getArity();i++) { if (!this.getTypeAt(i).isSortKeyType()) { return false; } } return true; }
public static boolean isSortKey(int fieldPos, TypeInformation<?> type) { if (!type.isTupleType() || !(type instanceof CompositeType)) { throw new InvalidProgramException("Specifying keys via field positions is only valid " + "for tuple data types. Type: " + type); } if (type.getArity() == 0) { throw new InvalidProgramException("Tuple size must be greater than 0. Size: " + type.getArity()); } if(fieldPos < 0 || fieldPos >= type.getArity()) { throw new IndexOutOfBoundsException("Tuple position is out of range: " + fieldPos); } TypeInformation<?> sortKeyType = ((CompositeType<?>)type).getTypeAt(fieldPos); return sortKeyType.isSortKeyType(); }