SelectHelpers { public static Schema getOutputSchema( Schema inputSchema, FieldAccessDescriptor fieldAccessDescriptor) { return getOutputSchemaTrackingNullable(inputSchema, fieldAccessDescriptor, false); }  static Schema getOutputSchema(
      Schema inputSchema, FieldAccessDescriptor fieldAccessDescriptor); static RowSelector getRowSelectorOptimized(
      Schema inputSchema, FieldAccessDescriptor fieldAccessDescriptor); static RowSelector getRowSelector(
      Schema inputSchema, FieldAccessDescriptor fieldAccessDescriptor); static FieldAccessDescriptor allLeavesDescriptor(
      Schema schema, SerializableFunction<List<String>, String> nameFn); static final SerializableFunction<List<String>, String> CONCAT_FIELD_NAMES; static final SerializableFunction<List<String>, String> KEEP_NESTED_NAME; }
@Test public void testNullableSchema() { FieldAccessDescriptor fieldAccessDescriptor1 = FieldAccessDescriptor.withFieldNames("nested.field1").resolve(NESTED_NULLABLE_SCHEMA); Schema schema1 = SelectHelpers.getOutputSchema(NESTED_NULLABLE_SCHEMA, fieldAccessDescriptor1); Schema expectedSchema1 = Schema.builder().addNullableField("field1", FieldType.STRING).build(); assertEquals(expectedSchema1, schema1); FieldAccessDescriptor fieldAccessDescriptor2 = FieldAccessDescriptor.withFieldNames("nested.*").resolve(NESTED_NULLABLE_SCHEMA); Schema schema2 = SelectHelpers.getOutputSchema(NESTED_NULLABLE_SCHEMA, fieldAccessDescriptor2); Schema expectedSchema2 = Schema.builder() .addNullableField("field1", FieldType.STRING) .addNullableField("field2", FieldType.INT32) .addNullableField("field3", FieldType.DOUBLE) .addNullableField("field_extra", FieldType.STRING) .build(); assertEquals(expectedSchema2, schema2); }
@Test public void testNullableSchemaArray() { FieldAccessDescriptor fieldAccessDescriptor1 = FieldAccessDescriptor.withFieldNames("nestedArray.field1").resolve(NESTED_NULLABLE_SCHEMA); Schema schema1 = SelectHelpers.getOutputSchema(NESTED_NULLABLE_SCHEMA, fieldAccessDescriptor1); Schema expectedSchema1 = Schema.builder().addNullableField("field1", FieldType.array(FieldType.STRING)).build(); assertEquals(expectedSchema1, schema1); FieldAccessDescriptor fieldAccessDescriptor2 = FieldAccessDescriptor.withFieldNames("nestedArray.*").resolve(NESTED_NULLABLE_SCHEMA); Schema schema2 = SelectHelpers.getOutputSchema(NESTED_NULLABLE_SCHEMA, fieldAccessDescriptor2); Schema expectedSchema2 = Schema.builder() .addNullableField("field1", FieldType.array(FieldType.STRING)) .addNullableField("field2", FieldType.array(FieldType.INT32)) .addNullableField("field3", FieldType.array(FieldType.DOUBLE)) .addNullableField("field_extra", FieldType.array(FieldType.STRING)) .build(); assertEquals(expectedSchema2, schema2); }
@Test public void testNullableSchemaMap() { FieldAccessDescriptor fieldAccessDescriptor1 = FieldAccessDescriptor.withFieldNames("nestedMap.field1").resolve(NESTED_NULLABLE_SCHEMA); Schema schema1 = SelectHelpers.getOutputSchema(NESTED_NULLABLE_SCHEMA, fieldAccessDescriptor1); Schema expectedSchema1 = Schema.builder() .addNullableField("field1", FieldType.map(FieldType.STRING, FieldType.STRING)) .build(); assertEquals(expectedSchema1, schema1); FieldAccessDescriptor fieldAccessDescriptor2 = FieldAccessDescriptor.withFieldNames("nestedMap.*").resolve(NESTED_NULLABLE_SCHEMA); Schema schema2 = SelectHelpers.getOutputSchema(NESTED_NULLABLE_SCHEMA, fieldAccessDescriptor2); Schema expectedSchema2 = Schema.builder() .addNullableField("field1", FieldType.map(FieldType.STRING, FieldType.STRING)) .addNullableField("field2", FieldType.map(FieldType.STRING, FieldType.INT32)) .addNullableField("field3", FieldType.map(FieldType.STRING, FieldType.DOUBLE)) .addNullableField("field_extra", FieldType.map(FieldType.STRING, FieldType.STRING)) .build(); assertEquals(expectedSchema2, schema2); }