-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Fail on unknown JDBC type #1105
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 |
|---|---|---|
|
|
@@ -63,6 +63,7 @@ | |
| import static com.google.common.collect.ImmutableMap.toImmutableMap; | ||
| import static com.google.common.collect.ImmutableSet.toImmutableSet; | ||
| import static com.google.common.collect.Iterables.getOnlyElement; | ||
| import static io.prestosql.plugin.jdbc.BaseJdbcSessionProperties.getUnsupportedTypeHandlingStrategy; | ||
| import static io.prestosql.plugin.jdbc.JdbcErrorCode.JDBC_ERROR; | ||
| import static io.prestosql.plugin.jdbc.StandardColumnMappings.bigintWriteFunction; | ||
| import static io.prestosql.plugin.jdbc.StandardColumnMappings.booleanWriteFunction; | ||
|
|
@@ -248,12 +249,22 @@ public List<JdbcColumnHandle> getColumns(ConnectorSession session, JdbcTableHand | |
| resultSet.getInt("DECIMAL_DIGITS"), | ||
| Optional.empty()); | ||
| Optional<ColumnMapping> columnMapping = toPrestoType(session, connection, typeHandle); | ||
| // skip unsupported column types | ||
| String columnName = resultSet.getString("COLUMN_NAME"); | ||
| if (columnMapping.isPresent()) { | ||
| String columnName = resultSet.getString("COLUMN_NAME"); | ||
| boolean nullable = (resultSet.getInt("NULLABLE") != columnNoNulls); | ||
| columns.add(new JdbcColumnHandle(columnName, typeHandle, columnMapping.get().getType(), nullable)); | ||
| } | ||
| else { | ||
| UnsupportedTypeHandlingStrategy unsupportedTypeHandlingStrategy = getUnsupportedTypeHandlingStrategy(session); | ||
| switch (unsupportedTypeHandlingStrategy) { | ||
| case IGNORE: | ||
| break; | ||
|
Member
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.
|
||
| case FAIL: | ||
| throw new PrestoException(JDBC_ERROR, "Unsupported data type for column: " + columnName); | ||
|
Member
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. incl |
||
| default: | ||
| throw new IllegalStateException("Unknown unsupported type handling strategy: " + unsupportedTypeHandlingStrategy); | ||
| } | ||
| } | ||
| } | ||
| if (columns.isEmpty()) { | ||
| // In rare cases (e.g. PostgreSQL) a table might have no columns. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,13 +14,15 @@ | |
| package io.prestosql.plugin.jdbc; | ||
|
|
||
| import io.airlift.configuration.Config; | ||
| import io.airlift.configuration.ConfigDescription; | ||
| import io.airlift.configuration.ConfigSecuritySensitive; | ||
| import io.airlift.units.Duration; | ||
| import io.airlift.units.MinDuration; | ||
|
|
||
| import javax.annotation.Nullable; | ||
| import javax.validation.constraints.NotNull; | ||
|
|
||
| import static io.prestosql.plugin.jdbc.UnsupportedTypeHandlingStrategy.FAIL; | ||
| import static java.util.concurrent.TimeUnit.MINUTES; | ||
|
|
||
| public class BaseJdbcConfig | ||
|
|
@@ -32,6 +34,7 @@ public class BaseJdbcConfig | |
| private String passwordCredentialName; | ||
| private boolean caseInsensitiveNameMatching; | ||
| private Duration caseInsensitiveNameMatchingCacheTtl = new Duration(1, MINUTES); | ||
| private UnsupportedTypeHandlingStrategy unsupportedTypeHandlingStrategy = FAIL; | ||
|
Member
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. Do we have already enough data points to determine what the default behavior should actually be? |
||
|
|
||
| @NotNull | ||
| public String getConnectionUrl() | ||
|
|
@@ -124,4 +127,18 @@ public BaseJdbcConfig setCaseInsensitiveNameMatchingCacheTtl(Duration caseInsens | |
| this.caseInsensitiveNameMatchingCacheTtl = caseInsensitiveNameMatchingCacheTtl; | ||
| return this; | ||
| } | ||
|
|
||
| @NotNull | ||
| public UnsupportedTypeHandlingStrategy getUnsupportedTypeHandlingStrategy() | ||
| { | ||
| return unsupportedTypeHandlingStrategy; | ||
| } | ||
|
|
||
| @Config("unsupported-type.handling-strategy") | ||
|
Member
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.
I understand the enum is a preparation for an option to map unsupported columns to varchar (see also #186) |
||
| @ConfigDescription("Configures how unsupported column data types should be handled") | ||
| public BaseJdbcConfig setUnsupportedTypeHandlingStrategy(UnsupportedTypeHandlingStrategy unsupportedTypeHandlingStrategy) | ||
| { | ||
| this.unsupportedTypeHandlingStrategy = unsupportedTypeHandlingStrategy; | ||
| return this; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * 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.prestosql.plugin.jdbc; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import io.prestosql.spi.connector.ConnectorSession; | ||
| import io.prestosql.spi.session.PropertyMetadata; | ||
|
|
||
| import javax.inject.Inject; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static io.prestosql.spi.session.PropertyMetadata.enumProperty; | ||
|
|
||
| public final class BaseJdbcSessionProperties | ||
| implements SessionPropertiesProvider | ||
| { | ||
| public static final String UNSUPPORTED_TYPE_HANDLING_STRATEGY = "unsupported_type_handling_strategy"; | ||
|
|
||
| private final List<PropertyMetadata<?>> sessionProperties; | ||
|
|
||
| @Inject | ||
| public BaseJdbcSessionProperties(BaseJdbcConfig config) | ||
| { | ||
| sessionProperties = ImmutableList.of( | ||
| enumProperty( | ||
| UNSUPPORTED_TYPE_HANDLING_STRATEGY, | ||
| "Configures how unsupported column data types should be handled", | ||
| UnsupportedTypeHandlingStrategy.class, | ||
| config.getUnsupportedTypeHandlingStrategy(), | ||
| false)); | ||
| } | ||
|
|
||
| @Override | ||
| public List<PropertyMetadata<?>> getSessionProperties() | ||
| { | ||
| return sessionProperties; | ||
| } | ||
|
|
||
| public static UnsupportedTypeHandlingStrategy getUnsupportedTypeHandlingStrategy(ConnectorSession session) | ||
| { | ||
| return session.getProperty(UNSUPPORTED_TYPE_HANDLING_STRATEGY, UnsupportedTypeHandlingStrategy.class); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| */ | ||
| package io.prestosql.plugin.jdbc; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.common.collect.ImmutableSet; | ||
| import io.airlift.bootstrap.LifeCycleManager; | ||
| import io.airlift.log.Logger; | ||
|
|
@@ -25,10 +26,12 @@ | |
| import io.prestosql.spi.connector.ConnectorSplitManager; | ||
| import io.prestosql.spi.connector.ConnectorTransactionHandle; | ||
| import io.prestosql.spi.procedure.Procedure; | ||
| import io.prestosql.spi.session.PropertyMetadata; | ||
| import io.prestosql.spi.transaction.IsolationLevel; | ||
|
|
||
| import javax.inject.Inject; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
@@ -53,6 +56,7 @@ public class JdbcConnector | |
| private final JdbcPageSinkProvider jdbcPageSinkProvider; | ||
| private final Optional<ConnectorAccessControl> accessControl; | ||
| private final Set<Procedure> procedures; | ||
| private final Set<SessionPropertiesProvider> sessionProperties; | ||
|
|
||
| private final ConcurrentMap<ConnectorTransactionHandle, JdbcMetadata> transactions = new ConcurrentHashMap<>(); | ||
|
|
||
|
|
@@ -64,7 +68,8 @@ public JdbcConnector( | |
| JdbcRecordSetProvider jdbcRecordSetProvider, | ||
| JdbcPageSinkProvider jdbcPageSinkProvider, | ||
| Optional<ConnectorAccessControl> accessControl, | ||
| Set<Procedure> procedures) | ||
| Set<Procedure> procedures, | ||
| Set<SessionPropertiesProvider> sessionProperties) | ||
| { | ||
| this.lifeCycleManager = requireNonNull(lifeCycleManager, "lifeCycleManager is null"); | ||
| this.jdbcMetadataFactory = requireNonNull(jdbcMetadataFactory, "jdbcMetadataFactory is null"); | ||
|
|
@@ -73,6 +78,7 @@ public JdbcConnector( | |
| this.jdbcPageSinkProvider = requireNonNull(jdbcPageSinkProvider, "jdbcPageSinkProvider is null"); | ||
| this.accessControl = requireNonNull(accessControl, "accessControl is null"); | ||
| this.procedures = ImmutableSet.copyOf(requireNonNull(procedures, "procedures is null")); | ||
| this.sessionProperties = requireNonNull(sessionProperties, "sessionProperties is null"); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -142,6 +148,14 @@ public Set<Procedure> getProcedures() | |
| return procedures; | ||
| } | ||
|
|
||
| @Override | ||
| public List<PropertyMetadata<?>> getSessionProperties() | ||
| { | ||
| ImmutableList.Builder builder = ImmutableList.<PropertyMetadata<?>>builder(); | ||
|
Member
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. raw usage of a generic class |
||
| this.sessionProperties.forEach(sessionPropertiesProvider -> builder.addAll(sessionPropertiesProvider.getSessionProperties())); | ||
| return builder.build(); | ||
| } | ||
|
|
||
| @Override | ||
| public final void shutdown() | ||
| { | ||
|
|
||
| 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.prestosql.plugin.jdbc; | ||
|
|
||
| import io.prestosql.spi.session.PropertyMetadata; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface SessionPropertiesProvider | ||
| { | ||
| List<PropertyMetadata<?>> getSessionProperties(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * 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.prestosql.plugin.jdbc; | ||
|
|
||
| public enum UnsupportedTypeHandlingStrategy | ||
| { | ||
| IGNORE, | ||
| FAIL, | ||
| /**/; | ||
| } |
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.
query should fail only when user actually tries to read data from such column