Skip to content

Commit

Permalink
Merge pull request GoogleCloudPlatform#1623 from VardhanThigle:date-fix
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 640006995
  • Loading branch information
cloud-teleport committed Jun 4, 2024
2 parents c2e1b6a + 422ca47 commit 896b33b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ private static DataSourceConfiguration getDataSourceConfiguration(JdbcIOWrapperC
StaticValueProvider.of(config.sourceDbURL()))
.withMaxConnections(Math.toIntExact(config.maxConnections()));

if (!config.sqlInitSeq().isEmpty()) {
dataSourceConfig = dataSourceConfig.withConnectionInitSqls(config.sqlInitSeq());
}

if (config.jdbcDriverJars() != null && !config.jdbcDriverJars().isEmpty()) {
dataSourceConfig = dataSourceConfig.withDriverJars(config.jdbcDriverJars());
}
Expand All @@ -289,6 +293,8 @@ private static DataSourceConfiguration getDataSourceConfiguration(JdbcIOWrapperC
if (!config.dbAuth().getPassword().get().isBlank()) {
dataSourceConfig = dataSourceConfig.withPassword(config.dbAuth().getPassword().get());
}

LOG.info("Final DatasourceConfiguration: {}", dataSourceConfig);
return dataSourceConfig;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,16 @@ public abstract class JdbcIOWrapperConfig {
@Nullable
public abstract Integer maxFetchSize();

/** Sequence of Sql Init statements for the connection. */
public abstract ImmutableList<String> sqlInitSeq();

public static Builder builderWithMySqlDefaults() {
return new AutoValue_JdbcIOWrapperConfig.Builder()
.setSchemaMapperType(MySqlConfigDefaults.DEFAULT_MYSQL_SCHEMA_MAPPER_TYPE)
.setDialectAdapter(MySqlConfigDefaults.DEFAULT_MYSQL_DIALECT_ADAPTER)
.setValueMappingsProvider(MySqlConfigDefaults.DEFAULT_MYSQL_VALUE_MAPPING_PROVIDER)
.setMaxConnections(MySqlConfigDefaults.DEFAULT_MYSQL_MAX_CONNECTIONS)
.setSqlInitSeq(MySqlConfigDefaults.DEFAULT_MYSQL_INIT_SEQ)
.setSchemaDiscoveryBackOff(MySqlConfigDefaults.DEFAULT_MYSQL_SCHEMA_DISCOVERY_BACKOFF)
.setTables(ImmutableList.of())
.setTableVsPartitionColumns(ImmutableMap.of())
Expand Down Expand Up @@ -136,6 +140,8 @@ public abstract Builder setTableVsPartitionColumns(

public abstract Builder setMaxFetchSize(Integer value);

public abstract Builder setSqlInitSeq(ImmutableList<String> value);

public abstract Builder setMaxConnections(Long value);

public abstract JdbcIOWrapperConfig build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.google.cloud.teleport.v2.source.reader.io.jdbc.rowmapper.JdbcValueMappingsProvider;
import com.google.cloud.teleport.v2.source.reader.io.jdbc.rowmapper.provider.MysqlJdbcValueMappings;
import com.google.cloud.teleport.v2.source.reader.io.schema.typemapping.UnifiedTypeMapper.MapperType;
import com.google.common.collect.ImmutableList;
import java.util.Calendar;
import org.apache.beam.sdk.util.FluentBackoff;

// TODO: Fine-tune the defaults based on benchmarking.
Expand Down Expand Up @@ -54,5 +56,24 @@ public class MySqlConfigDefaults {
public static final long DEFAULT_MYSQL_RECONNECT_ATTEMPTS = 10L;
public static final FluentBackoff DEFAULT_MYSQL_SCHEMA_DISCOVERY_BACKOFF = FluentBackoff.DEFAULT;

/**
* Default Initialization Sequence for the JDBC connection.
*
* <p>
*
* <ol>
* <li>Session Timezone: session time zone is set to UTC to always retrieve timestamp in UTC.
* The most idomatic way to achieve this via jdbc would be to pass a {@link Calendar} object
* initialized to UTC to {@link java.sql.ResultSet#getTimestamp(String, Calendar)} api
* (which is what we do in {@link MysqlJdbcValueMappings}), but due to bugs like <a
* href="https://bugs.mysql.com/bug.php?id=95644">Bug#95644</a>, <a
* href="https://bugs.mysql.com/bug.php?id=96276">Bug#96276</a>, <a
* href="https://bugs.mysql.com/bug.php?id=93444">Bug#93444</a>, etc. in the older drivers,
* we are also setting the session timezone to UTC.
* </ol>
*/
public static final ImmutableList<String> DEFAULT_MYSQL_INIT_SEQ =
ImmutableList.of("SET TIME_ZONE = 'UTC'");

private MySqlConfigDefaults() {}
}

0 comments on commit 896b33b

Please sign in to comment.