Skip to content

Commit 19b1944

Browse files
committed
Improvement of ResultSet metadata
1 parent 5d545c0 commit 19b1944

File tree

23 files changed

+400
-63
lines changed

23 files changed

+400
-63
lines changed

client/trino-client/src/main/java/io/trino/client/Column.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,98 @@
1818
import com.google.errorprone.annotations.Immutable;
1919

2020
import java.util.Objects;
21+
import java.util.Optional;
2122

2223
import static java.util.Objects.requireNonNull;
2324

2425
@Immutable
2526
public class Column
2627
{
28+
private final Optional<String> catalog;
29+
private final Optional<String> schema;
30+
private final Optional<String> table;
2731
private final String name;
32+
private final Optional<String> label;
33+
private final Optional<Boolean> autoIncrement;
34+
private final Optional<Boolean> readOnly;
2835
private final String type;
2936
private final ClientTypeSignature typeSignature;
3037

38+
public Column(String name, String type, ClientTypeSignature typeSignature)
39+
{
40+
this(Optional.empty(), Optional.empty(), Optional.empty(), name, Optional.of(name), Optional.empty(), Optional.empty(), type, typeSignature);
41+
}
42+
43+
public Column(String catalog, String schema, String table, String name, String label, String type, ClientTypeSignature typeSignature)
44+
{
45+
this(Optional.of(catalog), Optional.of(schema), Optional.of(table), name, Optional.of(label), Optional.empty(), Optional.empty(), type, typeSignature);
46+
}
47+
3148
@JsonCreator
3249
public Column(
50+
@JsonProperty("catalog") Optional<String> catalog,
51+
@JsonProperty("schema") Optional<String> schema,
52+
@JsonProperty("table") Optional<String> table,
3353
@JsonProperty("name") String name,
54+
@JsonProperty("label") Optional<String> label,
55+
@JsonProperty("autoIncrement") Optional<Boolean> autoIncrement,
56+
@JsonProperty("readOnly") Optional<Boolean> readOnly,
3457
@JsonProperty("type") String type,
3558
@JsonProperty("typeSignature") ClientTypeSignature typeSignature)
3659
{
60+
this.catalog = requireNonNull(catalog, "catalog is null");
61+
this.schema = requireNonNull(schema, "schema is null");
62+
this.table = requireNonNull(table, "table is null");
3763
this.name = requireNonNull(name, "name is null");
64+
this.label = requireNonNull(label, "label is null");
65+
this.autoIncrement = requireNonNull(autoIncrement, "autoIncrement is null");
66+
this.readOnly = requireNonNull(readOnly, "readOnly is null");
3867
this.type = requireNonNull(type, "type is null");
3968
this.typeSignature = typeSignature;
4069
}
4170

71+
@JsonProperty
72+
public Optional<String> getCatalog()
73+
{
74+
return catalog;
75+
}
76+
77+
@JsonProperty
78+
public Optional<String> getSchema()
79+
{
80+
return schema;
81+
}
82+
83+
@JsonProperty
84+
public Optional<String> getTable()
85+
{
86+
return table;
87+
}
88+
4289
@JsonProperty
4390
public String getName()
4491
{
4592
return name;
4693
}
4794

95+
@JsonProperty
96+
public Optional<String> getLabel()
97+
{
98+
return label;
99+
}
100+
101+
@JsonProperty
102+
public Optional<Boolean> getAutoIncrement()
103+
{
104+
return autoIncrement;
105+
}
106+
107+
@JsonProperty
108+
public Optional<Boolean> getReadOnly()
109+
{
110+
return readOnly;
111+
}
112+
48113
@JsonProperty
49114
public String getType()
50115
{

client/trino-client/src/test/java/io/trino/client/TestQueryResults.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ public class TestQueryResults
2929
" \"id\" : \"20160128_214710_00012_rk68b\",\n" +
3030
" \"infoUri\" : \"http://localhost:54855/query.html?20160128_214710_00012_rk68b\",\n" +
3131
" \"columns\" : [ {\n" +
32+
" \"catalog\" : \"_cat0\",\n" +
33+
" \"schema\" : \"_sch0\",\n" +
34+
" \"table\" : \"_tab0\",\n" +
3235
" \"name\" : \"_col0\",\n" +
36+
" \"label\" : \"_lab0\",\n" +
3337
" \"type\" : \"bigint\",\n" +
3438
" \"typeSignature\" : {\n" +
3539
" \"rawType\" : \"varchar\",\n" +

client/trino-jdbc/src/main/java/io/trino/jdbc/AbstractTrinoResultSet.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,11 +1970,13 @@ private static List<ColumnInfo> getColumnInfo(List<Column> columns)
19701970
ImmutableList.Builder<ColumnInfo> list = ImmutableList.builderWithExpectedSize(columns.size());
19711971
for (Column column : columns) {
19721972
ColumnInfo.Builder builder = new ColumnInfo.Builder()
1973-
.setCatalogName("") // TODO
1974-
.setSchemaName("") // TODO
1975-
.setTableName("") // TODO
1973+
.setCatalogName(column.getCatalog().orElse(""))
1974+
.setSchemaName(column.getSchema().orElse(""))
1975+
.setTableName(column.getTable().orElse(""))
19761976
.setColumnLabel(column.getName())
1977-
.setColumnName(column.getName()) // TODO
1977+
.setColumnName(column.getLabel().orElse(column.getName()))
1978+
.setAutoIncrement(column.getAutoIncrement().orElse(false))
1979+
.setReadOnly(column.getReadOnly().orElse(true))
19781980
.setColumnTypeSignature(column.getTypeSignature())
19791981
.setNullable(Nullable.UNKNOWN)
19801982
.setCurrency(false);

client/trino-jdbc/src/main/java/io/trino/jdbc/ColumnInfo.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class ColumnInfo
3737
private final ClientTypeSignature columnTypeSignature;
3838
private final Nullable nullable;
3939
private final boolean currency;
40+
private final boolean autoIncrement;
41+
private final boolean readOnly;
4042
private final boolean signed;
4143
private final int precision;
4244
private final int scale;
@@ -58,6 +60,8 @@ public ColumnInfo(
5860
ClientTypeSignature columnTypeSignature,
5961
Nullable nullable,
6062
boolean currency,
63+
boolean autoIncrement,
64+
boolean readOnly,
6165
boolean signed,
6266
int precision,
6367
int scale,
@@ -73,6 +77,8 @@ public ColumnInfo(
7377
this.columnTypeSignature = requireNonNull(columnTypeSignature, "columnTypeSignature is null");
7478
this.nullable = requireNonNull(nullable, "nullable is null");
7579
this.currency = currency;
80+
this.autoIncrement = autoIncrement;
81+
this.readOnly = readOnly;
7682
this.signed = signed;
7783
this.precision = precision;
7884
this.scale = scale;
@@ -278,6 +284,16 @@ public boolean isCurrency()
278284
return currency;
279285
}
280286

287+
public boolean isAutoIncrement()
288+
{
289+
return autoIncrement;
290+
}
291+
292+
public boolean isReadOnly()
293+
{
294+
return readOnly;
295+
}
296+
281297
public boolean isSigned()
282298
{
283299
return signed;
@@ -330,6 +346,8 @@ static class Builder
330346
private ClientTypeSignature columnTypeSignature;
331347
private Nullable nullable;
332348
private boolean currency;
349+
private boolean autoIncrement;
350+
private boolean readOnly;
333351
private boolean signed;
334352
private int precision;
335353
private int scale;
@@ -369,6 +387,18 @@ public Builder setCurrency(boolean currency)
369387
return this;
370388
}
371389

390+
public Builder setAutoIncrement(boolean autoIncrement)
391+
{
392+
this.autoIncrement = autoIncrement;
393+
return this;
394+
}
395+
396+
public Builder setReadOnly(boolean readOnly)
397+
{
398+
this.readOnly = readOnly;
399+
return this;
400+
}
401+
372402
public Builder setSigned(boolean signed)
373403
{
374404
this.signed = signed;
@@ -432,6 +462,8 @@ public ColumnInfo build()
432462
nullable,
433463
currency,
434464
signed,
465+
autoIncrement,
466+
readOnly,
435467
precision,
436468
scale,
437469
columnDisplaySize,

client/trino-jdbc/src/main/java/io/trino/jdbc/TrinoResultSetMetaData.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public int getColumnCount()
5050
public boolean isAutoIncrement(int column)
5151
throws SQLException
5252
{
53-
return false;
53+
return column(column).isAutoIncrement();
5454
}
5555

5656
@Override
@@ -171,21 +171,21 @@ public String getColumnTypeName(int column)
171171
public boolean isReadOnly(int column)
172172
throws SQLException
173173
{
174-
return true;
174+
return column(column).isReadOnly();
175175
}
176176

177177
@Override
178178
public boolean isWritable(int column)
179179
throws SQLException
180180
{
181-
return false;
181+
return !column(column).isReadOnly();
182182
}
183183

184184
@Override
185185
public boolean isDefinitelyWritable(int column)
186186
throws SQLException
187187
{
188-
return false;
188+
return !column(column).isReadOnly();
189189
}
190190

191191
@Override

0 commit comments

Comments
 (0)