Timezone variable support one digital time (#2513)
Support time zone variable like "-8:00","+8:00","8:00" Time zone variable like "-8:00" is illegal in time-zone ID ,so we mush transfer it to standard format
This commit is contained in:
@ -96,6 +96,7 @@ public class CreateRoutineLoadStmtTest {
|
||||
String topicName = "topic1";
|
||||
String serverAddress = "127.0.0.1:8080";
|
||||
String kafkaPartitionString = "1,2,3";
|
||||
String timeZone = "8:00";
|
||||
List<String> partitionNameString = Lists.newArrayList();
|
||||
partitionNameString.add("p1");
|
||||
PartitionNames partitionNames = new PartitionNames(partitionNameString);
|
||||
@ -108,6 +109,7 @@ public class CreateRoutineLoadStmtTest {
|
||||
loadPropertyList.add(partitionNames);
|
||||
Map<String, String> properties = Maps.newHashMap();
|
||||
properties.put(CreateRoutineLoadStmt.DESIRED_CONCURRENT_NUMBER_PROPERTY, "2");
|
||||
properties.put(LoadStmt.TIMEZONE, timeZone);
|
||||
String typeName = LoadDataSourceType.KAFKA.name();
|
||||
Map<String, String> customProperties = Maps.newHashMap();
|
||||
|
||||
@ -134,6 +136,7 @@ public class CreateRoutineLoadStmtTest {
|
||||
Assert.assertEquals(0, createRoutineLoadStmt.getMaxErrorNum());
|
||||
Assert.assertEquals(serverAddress, createRoutineLoadStmt.getKafkaBrokerList());
|
||||
Assert.assertEquals(topicName, createRoutineLoadStmt.getKafkaTopic());
|
||||
Assert.assertEquals("+08:00", createRoutineLoadStmt.getTimezone());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@ import org.apache.doris.catalog.PrimitiveType;
|
||||
import org.apache.doris.catalog.ScalarType;
|
||||
import org.apache.doris.common.AnalysisException;
|
||||
|
||||
import org.apache.doris.common.DdlException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -134,4 +135,23 @@ public class TimeUtilsTest {
|
||||
Assert.assertEquals(20150301120000L, datetime.getRealValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTimezone() throws AnalysisException {
|
||||
try {
|
||||
Assert.assertEquals("CST", TimeUtils.checkTimeZoneValidAndStandardize("CST"));
|
||||
Assert.assertEquals("+08:00", TimeUtils.checkTimeZoneValidAndStandardize("+08:00"));
|
||||
Assert.assertEquals("+08:00", TimeUtils.checkTimeZoneValidAndStandardize("+8:00"));
|
||||
Assert.assertEquals("-08:00", TimeUtils.checkTimeZoneValidAndStandardize("-8:00"));
|
||||
Assert.assertEquals("+08:00", TimeUtils.checkTimeZoneValidAndStandardize("8:00"));
|
||||
} catch (DdlException ex) {
|
||||
Assert.fail();
|
||||
}
|
||||
try {
|
||||
TimeUtils.checkTimeZoneValidAndStandardize("FOO");
|
||||
Assert.fail();
|
||||
} catch (DdlException ex) {
|
||||
Assert.assertTrue(ex.getMessage().contains("Unknown or incorrect time zone: 'FOO'"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -124,6 +124,18 @@ public class VariableMgrTest {
|
||||
VariableMgr.setVar(var, setVar4);
|
||||
Assert.assertEquals(2L, var.getSqlMode());
|
||||
|
||||
// Test checkTimeZoneValidAndStandardize
|
||||
SetVar setVar5 = new SetVar(SetType.GLOBAL, "time_zone", new StringLiteral("+8:00"));
|
||||
VariableMgr.setVar(var, setVar5);
|
||||
Assert.assertEquals("+08:00", VariableMgr.newSessionVariable().getTimeZone());
|
||||
|
||||
SetVar setVar6 = new SetVar(SetType.GLOBAL, "time_zone", new StringLiteral("8:00"));
|
||||
VariableMgr.setVar(var, setVar6);
|
||||
Assert.assertEquals("+08:00", VariableMgr.newSessionVariable().getTimeZone());
|
||||
|
||||
SetVar setVar7 = new SetVar(SetType.GLOBAL, "time_zone", new StringLiteral("-8:00"));
|
||||
VariableMgr.setVar(var, setVar7);
|
||||
Assert.assertEquals("-08:00", VariableMgr.newSessionVariable().getTimeZone());
|
||||
}
|
||||
|
||||
@Test(expected = DdlException.class)
|
||||
|
||||
Reference in New Issue
Block a user