-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Support column properties with jdbc connector #25174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.trino.plugin.jdbc; | ||
|
|
||
| import io.trino.spi.session.PropertyMetadata; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface ColumnPropertiesProvider | ||
| { | ||
| List<PropertyMetadata<?>> getColumnProperties(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,11 +40,12 @@ public final class JdbcColumnHandle | |
| private final Type columnType; | ||
| private final boolean nullable; | ||
| private final Optional<String> comment; | ||
| private final boolean autoIncrement; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feel like maybe we could make this filed to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| // All and only required fields | ||
| public JdbcColumnHandle(String columnName, JdbcTypeHandle jdbcTypeHandle, Type columnType) | ||
| { | ||
| this(columnName, jdbcTypeHandle, columnType, true, Optional.empty()); | ||
| this(columnName, jdbcTypeHandle, columnType, true, Optional.empty(), false); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -57,13 +58,15 @@ public JdbcColumnHandle( | |
| @JsonProperty("jdbcTypeHandle") JdbcTypeHandle jdbcTypeHandle, | ||
| @JsonProperty("columnType") Type columnType, | ||
| @JsonProperty("nullable") boolean nullable, | ||
| @JsonProperty("comment") Optional<String> comment) | ||
| @JsonProperty("comment") Optional<String> comment, | ||
| @JsonProperty("autoIncrement") boolean autoIncrement) | ||
| { | ||
| this.columnName = requireNonNull(columnName, "columnName is null"); | ||
| this.jdbcTypeHandle = requireNonNull(jdbcTypeHandle, "jdbcTypeHandle is null"); | ||
| this.columnType = requireNonNull(columnType, "columnType is null"); | ||
| this.nullable = nullable; | ||
| this.comment = requireNonNull(comment, "comment is null"); | ||
| this.autoIncrement = autoIncrement; | ||
| } | ||
|
|
||
| @JsonProperty | ||
|
|
@@ -96,6 +99,12 @@ public Optional<String> getComment() | |
| return comment; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public boolean isAutoIncrement() | ||
| { | ||
| return autoIncrement; | ||
| } | ||
|
|
||
| public ColumnMetadata getColumnMetadata() | ||
| { | ||
| return ColumnMetadata.builder() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not add the auto increment info here, so we can use it in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe different datasource will use different column properties, so different datasource will have their own |
||
|
|
@@ -147,6 +156,7 @@ public long getRetainedSizeInBytes() | |
| // columnType is not accounted for as the instances are cached (by TypeRegistry) and shared | ||
| return INSTANCE_SIZE | ||
| + sizeOf(nullable) | ||
| + sizeOf(autoIncrement) | ||
| + estimatedSizeOf(columnName) | ||
| + sizeOf(comment, SizeOf::estimatedSizeOf) | ||
| + jdbcTypeHandle.getRetainedSizeInBytes(); | ||
|
|
@@ -169,6 +179,7 @@ public static final class Builder | |
| private Type columnType; | ||
| private boolean nullable = true; | ||
| private Optional<String> comment = Optional.empty(); | ||
| private boolean autoIncrement; | ||
|
|
||
| public Builder() {} | ||
|
|
||
|
|
@@ -179,6 +190,7 @@ private Builder(JdbcColumnHandle handle) | |
| this.columnType = handle.getColumnType(); | ||
| this.nullable = handle.isNullable(); | ||
| this.comment = handle.getComment(); | ||
| this.autoIncrement = handle.isAutoIncrement(); | ||
| } | ||
|
|
||
| public Builder setColumnName(String columnName) | ||
|
|
@@ -211,14 +223,21 @@ public Builder setComment(Optional<String> comment) | |
| return this; | ||
| } | ||
|
|
||
| public Builder setAutoIncrement(boolean autoIncrement) | ||
| { | ||
| this.autoIncrement = autoIncrement; | ||
| return this; | ||
| } | ||
|
|
||
| public JdbcColumnHandle build() | ||
| { | ||
| return new JdbcColumnHandle( | ||
| columnName, | ||
| jdbcTypeHandle, | ||
| columnType, | ||
| nullable, | ||
| comment); | ||
| comment, | ||
| autoIncrement); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you move the section? Please separate a commit for moving.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Table properties or column properties are part of the table management. So I move it into
Schema and table managementsection