Skip to content
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

Merged
merged 1 commit into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -237,9 +238,11 @@ public RedshiftClient(
JdbcStatisticsConfig statisticsConfig,
QueryBuilder queryBuilder,
IdentifierMapping identifierMapping,
RemoteQueryModifier queryModifier)
RemoteQueryModifier queryModifier,
Copy link
Member

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

RedshiftConfig redshiftConfig)
{
super(config, "\"", connectionFactory, queryBuilder, identifierMapping, queryModifier);
this.legacyTypeMapping = redshiftConfig.isLegacyTypeMapping();
ConnectorExpressionRewriter<String> connectorExpressionRewriter = JdbcConnectorExpressionRewriterBuilder.newBuilder()
.addStandardRules(this::quoted)
.build();
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: todo -> TODO

if (legacyTypeMapping) {
return legacyToColumnMapping(session, type);
}

Optional<ColumnMapping> mapping = getForcedMappingToVarchar(type);
if (mapping.isPresent()) {
return mapping;
Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class RedshiftClientModule
@Override
public void setup(Binder binder)
{
configBinder(binder).bindConfig(RedshiftConfig.class);
binder.bind(JdbcClient.class).annotatedWith(ForBaseJdbc.class).to(RedshiftClient.class).in(SINGLETON);
newSetBinder(binder, ConnectorTableFunction.class).addBinding().toProvider(Query.class).in(SINGLETON);
configBinder(binder).bindConfig(JdbcStatisticsConfig.class);
Expand Down
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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use -> force
It has been used even before. Even more, it's used in other connectors, but as a fallback. Here it overrides improved mapping.

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);
}
}