[FLINK-36572][pipeline-connector][starrocks] Fix the issue that the local time zone is wrongly set

This closes  #3733.
pull/3751/head
Runkang He 2 months ago committed by GitHub
parent fb2a1d0c38
commit d63512ea19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -17,6 +17,7 @@
package org.apache.flink.cdc.connectors.starrocks.sink;
import org.apache.flink.cdc.common.annotation.VisibleForTesting;
import org.apache.flink.cdc.common.event.Event;
import org.apache.flink.cdc.common.sink.DataSink;
import org.apache.flink.cdc.common.sink.EventSinkProvider;
@ -78,4 +79,9 @@ public class StarRocksDataSink implements DataSink, Serializable {
sinkOptions.getPassword());
return new StarRocksMetadataApplier(catalog, tableCreateConfig, schemaChangeConfig);
}
@VisibleForTesting
public ZoneId getZoneId() {
return zoneId;
}
}

@ -51,7 +51,7 @@ public class StarRocksDataSinkFactory implements DataSinkFactory {
TableCreateConfig.from(context.getFactoryConfiguration());
SchemaChangeConfig schemaChangeConfig =
SchemaChangeConfig.from(context.getFactoryConfiguration());
String zoneStr = context.getFactoryConfiguration().get(PIPELINE_LOCAL_TIME_ZONE);
String zoneStr = context.getPipelineConfiguration().get(PIPELINE_LOCAL_TIME_ZONE);
ZoneId zoneId =
PIPELINE_LOCAL_TIME_ZONE.defaultValue().equals(zoneStr)
? ZoneId.systemDefault()

@ -30,6 +30,7 @@ import org.apache.flink.shaded.guava31.com.google.common.collect.ImmutableMap;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import java.time.ZoneId;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -150,4 +151,36 @@ public class StarRocksDataSinkFactoryTest {
conf, conf, Thread.currentThread().getContextClassLoader()));
Assertions.assertThat(dataSink).isInstanceOf(StarRocksDataSink.class);
}
@Test
void testCreateDataSinkWithSpecificedTimeZone() {
DataSinkFactory sinkFactory =
FactoryDiscoveryUtils.getFactoryByIdentifier("starrocks", DataSinkFactory.class);
Assertions.assertThat(sinkFactory).isInstanceOf(StarRocksDataSinkFactory.class);
Configuration factoryConfiguration =
Configuration.fromMap(
ImmutableMap.<String, String>builder()
.put("jdbc-url", "jdbc:mysql://127.0.0.1:9030")
.put("load-url", "127.0.0.1:8030")
.put("username", "root")
.put("password", "")
.build());
Configuration pipelineConfiguration =
Configuration.fromMap(
ImmutableMap.<String, String>builder()
.put("local-time-zone", "America/Los_Angeles")
.build());
DataSink dataSink =
sinkFactory.createDataSink(
new FactoryHelper.DefaultContext(
factoryConfiguration,
pipelineConfiguration,
Thread.currentThread().getContextClassLoader()));
Assertions.assertThat(dataSink).isInstanceOf(StarRocksDataSink.class);
ZoneId zoneId = ((StarRocksDataSink) dataSink).getZoneId();
ZoneId expectedZondId = ZoneId.of("America/Los_Angeles");
Assertions.assertThat(zoneId).isEqualTo(expectedZondId);
}
}

Loading…
Cancel
Save