@Override public int getColumnIndex(String columnName) { // Use the Type instance for field name lookup. Type instances are naturally shared by the // ResultSet, all Structs corresponding to rows in the read, and all Structs corresponding to // the values of ARRAY<STRUCT<...>> columns in the read, so this is the best location to // amortize lookup costs. return getType().getFieldIndex(columnName); }
@Override public int getColumnIndex(String columnName) { return getType().getFieldIndex(columnName); }
@Test public void structFieldIndexNotFound() { Type t = Type.struct(StructField.of("f1", Type.int64())); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Field not found: f2"); t.getFieldIndex("f2"); }
@Test public void struct() { Type t = Type.struct(StructField.of("f1", Type.int64()), StructField.of("f2", Type.string())); assertThat(t.getCode()).isEqualTo(Type.Code.STRUCT); // Exercise StructField equality. assertThat(t.getStructFields()) .containsExactly(StructField.of("f1", Type.int64()), StructField.of("f2", Type.string())) .inOrder(); // Exercise StructField getters. assertThat(t.getStructFields().get(0).getName()).isEqualTo("f1"); assertThat(t.getStructFields().get(0).getType()).isEqualTo(Type.int64()); assertThat(t.getStructFields().get(1).getName()).isEqualTo("f2"); assertThat(t.getStructFields().get(1).getType()).isEqualTo(Type.string()); assertThat(t.toString()).isEqualTo("STRUCT<f1 INT64, f2 STRING>"); assertThat(t.getFieldIndex("f1")).isEqualTo(0); assertThat(t.getFieldIndex("f2")).isEqualTo(1); assertProtoEquals( t.toProto(), "code: STRUCT struct_type { fields { name: 'f1' type { code: INT64 } }" + " fields { name: 'f2' type { code: STRING } } }"); }
@Test public void structFieldIndexAmbiguous() { Type t = Type.struct(StructField.of("f1", Type.int64()), StructField.of("f1", Type.string())); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Ambiguous field name: f1"); t.getFieldIndex("f1"); }
@Override public int getColumnIndex(String columnName) { // Use the Type instance for field name lookup. Type instances are naturally shared by the // ResultSet, all Structs corresponding to rows in the read, and all Structs corresponding to // the values of ARRAY<STRUCT<...>> columns in the read, so this is the best location to // amortize lookup costs. return getType().getFieldIndex(columnName); }
@Override public int getColumnIndex(String columnName) { return getType().getFieldIndex(columnName); }