/** * Creates a {@link RowTypeInfo} with projected fields. * * @param rowType The original RowTypeInfo whose fields are projected * @param fieldMapping The field mapping of the projection * @return A RowTypeInfo with projected fields. */ public static RowTypeInfo projectFields(RowTypeInfo rowType, int[] fieldMapping) { TypeInformation[] fieldTypes = new TypeInformation[fieldMapping.length]; String[] fieldNames = new String[fieldMapping.length]; for (int i = 0; i < fieldMapping.length; i++) { fieldTypes[i] = rowType.getTypeAt(fieldMapping[i]); fieldNames[i] = rowType.getFieldNames()[fieldMapping[i]]; } return new RowTypeInfo(fieldTypes, fieldNames); } }
TypeInformation<X> fieldType = this.getTypeAt(fieldIndex);
@Test public void testGetTypeAt() { RowTypeInfo typeInfo = new RowTypeInfo(typeList); assertArrayEquals(new String[]{"f0", "f1", "f2"}, typeInfo.getFieldNames()); assertEquals(BasicTypeInfo.STRING_TYPE_INFO, typeInfo.getTypeAt("f2")); assertEquals(BasicTypeInfo.SHORT_TYPE_INFO, typeInfo.getTypeAt("f1.f0")); assertEquals(BasicTypeInfo.BIG_DEC_TYPE_INFO, typeInfo.getTypeAt("f1.1")); }
@Test public void testCustomFieldNames() { String[] fieldNames = new String[]{"int", "row", "string"}; RowTypeInfo typeInfo1 = new RowTypeInfo(typeList, new String[]{"int", "row", "string"}); assertArrayEquals(new String[]{"int", "row", "string"}, typeInfo1.getFieldNames()); assertEquals(BasicTypeInfo.STRING_TYPE_INFO, typeInfo1.getTypeAt("string")); assertEquals(BasicTypeInfo.STRING_TYPE_INFO, typeInfo1.getTypeAt(2)); assertEquals(BasicTypeInfo.SHORT_TYPE_INFO, typeInfo1.getTypeAt("row.0")); assertEquals(BasicTypeInfo.BIG_DEC_TYPE_INFO, typeInfo1.getTypeAt("row.f1")); // change the names in fieldNames fieldNames[1] = "composite"; RowTypeInfo typeInfo2 = new RowTypeInfo(typeList, fieldNames); // make sure the field names are deep copied assertArrayEquals(new String[]{"int", "row", "string"}, typeInfo1.getFieldNames()); assertArrayEquals(new String[]{"int", "composite", "string"}, typeInfo2.getFieldNames()); }
@Override public TypeInformation<?>[] getPartitionFieldTypes() { if (!isPartitionTable) { return new TypeInformation[0]; } else { return Arrays.asList(partitionColNames).stream() .map(s -> rowTypeInfo.getTypeAt(s)) .collect(Collectors.toList()) .toArray(new TypeInformation[partitionColNames.length]); } }
public TypeInformation getFieldType(String tableName, String fieldName){ ScopeChild scopeChild = aliasMap.get(tableName); if(scopeChild == null){ throw new RuntimeException("can't find "); } RowTypeInfo rowTypeInfo = scopeChild.getRowTypeInfo(); int index = rowTypeInfo.getFieldIndex(fieldName); if(index == -1){ throw new RuntimeException("can't find field: " + fieldName); } return rowTypeInfo.getTypeAt(index); }
/** * Creates a {@link RowTypeInfo} with projected fields. * * @param rowType The original RowTypeInfo whose fields are projected * @param fieldMapping The field mapping of the projection * @return A RowTypeInfo with projected fields. */ public static RowTypeInfo projectFields(RowTypeInfo rowType, int[] fieldMapping) { TypeInformation[] fieldTypes = new TypeInformation[fieldMapping.length]; String[] fieldNames = new String[fieldMapping.length]; for (int i = 0; i < fieldMapping.length; i++) { fieldTypes[i] = rowType.getTypeAt(fieldMapping[i]); fieldNames[i] = rowType.getFieldNames()[fieldMapping[i]]; } return new RowTypeInfo(fieldTypes, fieldNames); } }
/** * Creates a {@link RowTypeInfo} with projected fields. * * @param rowType The original RowTypeInfo whose fields are projected * @param fieldMapping The field mapping of the projection * @return A RowTypeInfo with projected fields. */ public static RowTypeInfo projectFields(RowTypeInfo rowType, int[] fieldMapping) { TypeInformation[] fieldTypes = new TypeInformation[fieldMapping.length]; String[] fieldNames = new String[fieldMapping.length]; for (int i = 0; i < fieldMapping.length; i++) { fieldTypes[i] = rowType.getTypeAt(fieldMapping[i]); fieldNames[i] = rowType.getFieldNames()[fieldMapping[i]]; } return new RowTypeInfo(fieldTypes, fieldNames); } }
TypeInformation<X> fieldType = this.getTypeAt(fieldIndex);
TypeInformation<X> fieldType = this.getTypeAt(fieldIndex);