-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Add config property to disable new Redshift type mappings #15513
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 |
---|---|---|
|
@@ -229,6 +229,7 @@ public class RedshiftClient | |
private final AggregateFunctionRewriter<JdbcExpression, String> aggregateFunctionRewriter; | ||
private final boolean statisticsEnabled; | ||
private final RedshiftTableStatisticsReader statisticsReader; | ||
private final boolean legacyTypeMapping; | ||
|
||
@Inject | ||
public RedshiftClient( | ||
|
@@ -237,9 +238,11 @@ public RedshiftClient( | |
JdbcStatisticsConfig statisticsConfig, | ||
QueryBuilder queryBuilder, | ||
IdentifierMapping identifierMapping, | ||
RemoteQueryModifier queryModifier) | ||
RemoteQueryModifier queryModifier, | ||
RedshiftConfig redshiftConfig) | ||
{ | ||
super(config, "\"", connectionFactory, queryBuilder, identifierMapping, queryModifier); | ||
this.legacyTypeMapping = redshiftConfig.isLegacyTypeMapping(); | ||
ConnectorExpressionRewriter<String> connectorExpressionRewriter = JdbcConnectorExpressionRewriterBuilder.newBuilder() | ||
.addStandardRules(this::quoted) | ||
.build(); | ||
|
@@ -467,6 +470,11 @@ protected void verifyColumnName(DatabaseMetaData databaseMetadata, String column | |
@Override | ||
public Optional<ColumnMapping> toColumnMapping(ConnectorSession session, Connection connection, JdbcTypeHandle type) | ||
{ | ||
// todo remove this when legacy type mapping is no longer supported | ||
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. nit: |
||
if (legacyTypeMapping) { | ||
return legacyToColumnMapping(session, type); | ||
} | ||
|
||
Optional<ColumnMapping> mapping = getForcedMappingToVarchar(type); | ||
if (mapping.isPresent()) { | ||
return mapping; | ||
|
@@ -573,6 +581,11 @@ private Optional<ColumnMapping> legacyToColumnMapping(ConnectorSession session, | |
@Override | ||
public WriteMapping toWriteMapping(ConnectorSession session, Type type) | ||
{ | ||
// todo remove this when legacy type mapping is no longer supported | ||
if (legacyTypeMapping) { | ||
return legacyToWriteMapping(type); | ||
} | ||
|
||
if (BOOLEAN.equals(type)) { | ||
return WriteMapping.booleanMapping("boolean", booleanWriteFunction()); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* 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.redshift; | ||
|
||
import io.airlift.configuration.Config; | ||
|
||
public class RedshiftConfig | ||
{ | ||
private boolean legacyTypeMapping; | ||
|
||
public boolean isLegacyTypeMapping() | ||
{ | ||
return legacyTypeMapping; | ||
} | ||
|
||
@Config("redshift.use-legacy-type-mapping") | ||
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.
|
||
public RedshiftConfig setLegacyTypeMapping(boolean legacyTypeMapping) | ||
{ | ||
this.legacyTypeMapping = legacyTypeMapping; | ||
return this; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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.redshift; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.Map; | ||
|
||
import static io.airlift.configuration.testing.ConfigAssertions.assertFullMapping; | ||
import static io.airlift.configuration.testing.ConfigAssertions.assertRecordedDefaults; | ||
import static io.airlift.configuration.testing.ConfigAssertions.recordDefaults; | ||
|
||
public class TestRedshiftConfig | ||
{ | ||
@Test | ||
public void testDefaults() | ||
{ | ||
assertRecordedDefaults(recordDefaults(RedshiftConfig.class) | ||
.setLegacyTypeMapping(false)); | ||
} | ||
|
||
@Test | ||
public void testExplicitPropertyMappings() | ||
{ | ||
Map<String, String> properties = ImmutableMap.<String, String>builder() | ||
.put("redshift.use-legacy-type-mapping", "true") | ||
.buildOrThrow(); | ||
|
||
RedshiftConfig expected = new RedshiftConfig() | ||
.setLegacyTypeMapping(true); | ||
|
||
assertFullMapping(properties, expected); | ||
} | ||
} |
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.
nit: queryModifier is always the last arg in *Client classes