Skip to content

Commit a07cf9c

Browse files
committed
修复 0.49 版本一些问题
1 parent 3366b2a commit a07cf9c

File tree

6 files changed

+50
-21
lines changed

6 files changed

+50
-21
lines changed

odps-sdk/odps-sdk-commons/src/main/java/com/aliyun/odps/data/AbstractChar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ public String toString() {
6060
}
6161

6262
public int length() {
63-
return value.length();
63+
return value.codePointCount(0, value.length());
6464
}
6565
}

odps-sdk/odps-sdk-commons/src/test/java/com/aliyun/odps/data/ArrayRecordTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,4 +875,23 @@ public void testNewDateTypeInMap() {
875875

876876
}
877877

878+
@Test
879+
public void testVarcharOverFlow() {
880+
// make sure count char but not count length in varchar and char
881+
TableSchema tableSchema = new TableSchema();
882+
tableSchema.addColumn(new Column("varchar", TypeInfoFactory.getVarcharTypeInfo(11)));
883+
tableSchema.addColumn(new Column("char", TypeInfoFactory.getCharTypeInfo(11)));
884+
885+
ArrayRecord r = new ArrayRecord(tableSchema);
886+
String str = "184了776991\uD873\uDC56";
887+
Assert.assertEquals(11, new Varchar(str).length());
888+
889+
String str2 = "184了776991\uD83D\uDD3A";
890+
Assert.assertEquals(11, new Char(str2).length());
891+
892+
r.set(0, new Varchar(str));
893+
r.set(1, new Char(str2));
894+
895+
System.out.println(r);
896+
}
878897
}

odps-sdk/odps-sdk-core/src/main/java/com/aliyun/odps/CreateProjectParam.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ public CreateProjectParam groupName(String groupName) {
140140
return this;
141141
}
142142

143+
public CreateProjectParam defaultCtrlService(String defaultCtrlService) {
144+
this.projectModel.defaultCtrlService = defaultCtrlService;
145+
return this;
146+
}
147+
143148
Project.ProjectModel getProjectModel() {
144149
return this.projectModel;
145150
}

odps-sdk/odps-sdk-core/src/main/java/com/aliyun/odps/Project.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.util.List;
3030
import java.util.Map;
3131
import java.util.Map.Entry;
32-
import java.util.Optional;
3332

3433
import com.aliyun.odps.commons.transport.Headers;
3534
import com.aliyun.odps.commons.transport.Response;
@@ -180,6 +179,8 @@ static class ProjectModel {
180179
*/
181180
StorageTierInfo storageTierInfo;
182181

182+
@Element(name = "DefaultCtrlService", required = false)
183+
String defaultCtrlService;
183184
}
184185

185186
public static class ExternalProjectProperties {

odps-sdk/odps-sdk-core/src/main/java/com/aliyun/odps/data/converter/ObjectConverterFactory.java

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.time.format.ResolverStyle;
3333
import java.time.temporal.ChronoField;
3434
import java.util.Base64;
35+
import java.util.TimeZone;
3536

3637
import org.apache.commons.codec.binary.Hex;
3738

@@ -522,10 +523,11 @@ private static class DateConverter implements OdpsObjectConverter {
522523
parsePattern = DEFAULT_PARSE_PATTERN;
523524
}
524525
if (!strictMode) {
525-
legacyOutputFormatter = getLegacyDateTimeFormatter(outputPattern, OdpsType.DATE);
526+
legacyOutputFormatter =
527+
getLegacyDateTimeFormatter(outputPattern, config.timezone, OdpsType.DATE);
526528
}
527-
outputFormatter = getDateTimeFormatter(outputPattern, null, OdpsType.DATE);
528-
parseFormatter = getDateTimeFormatter(parsePattern, null, OdpsType.DATE);
529+
outputFormatter = getDateTimeFormatter(outputPattern, config.timezone, OdpsType.DATE);
530+
parseFormatter = getDateTimeFormatter(parsePattern, config.timezone, OdpsType.DATE);
529531
}
530532

531533
@Override
@@ -599,7 +601,7 @@ private static class DatetimeConverter implements OdpsObjectConverter {
599601
parseFormatter = getDateTimeFormatter(parsePattern, config.timezone, OdpsType.DATETIME);
600602
}
601603
if (!strictMode) {
602-
legacyOutputFormatter = getLegacyDateTimeFormatter(outputPattern, OdpsType.DATETIME);
604+
legacyOutputFormatter = getLegacyDateTimeFormatter(outputPattern, config.timezone, OdpsType.DATETIME);
603605
}
604606
outputFormatter = getDateTimeFormatter(outputPattern, config.timezone, OdpsType.DATETIME);
605607
}
@@ -662,17 +664,17 @@ private static abstract class AbstractTimestampFormatter implements OdpsObjectCo
662664

663665
private static class TimestampConverter extends AbstractTimestampFormatter {
664666
private final boolean useSqlFormat;
665-
667+
private final ZoneId timezone;
666668
TimestampConverter(OdpsRecordConverterBuilder.Config config) {
667669
this.useSqlFormat = config.useSqlFormat;
670+
this.timezone = config.timezone;
668671
String outputPattern = config.timestampOutputFormat;
669672
if (outputPattern != null) {
670673
outputFormatter =
671674
getDateTimeFormatter(outputPattern, config.timezone, OdpsType.TIMESTAMP);
672675
} else {
673676
outputFormatter = outputFormatter.withZone(config.timezone);
674677
}
675-
676678
String parsePattern = config.timestampParseFormat;
677679
if (parsePattern != null) {
678680
parseFormatter =
@@ -690,9 +692,7 @@ public String format(Object object, TypeInfo typeInfo, OdpsRecordConverter conve
690692
formattedStr = outputFormatter.format(i);
691693
} else if (object instanceof Timestamp) {
692694
Timestamp timestamp = (Timestamp) object;
693-
formattedStr =
694-
timestamp.getNanos() == 0 ? timestamp.toString().substring(0, 19)
695-
: timestamp.toString();
695+
formattedStr = outputFormatter.format(timestamp.toInstant().atZone(timezone));
696696
} else if (object instanceof LocalDateTime) {
697697
LocalDateTime localDateTime = (LocalDateTime) object;
698698
formattedStr = localDateTime.format(outputFormatter);
@@ -732,11 +732,11 @@ private static class TimestampNtzConverter extends AbstractTimestampFormatter {
732732

733733
String outputPattern = config.timestampNtzOutputFormat;
734734
if (outputPattern != null) {
735-
outputFormatter = getDateTimeFormatter(outputPattern, null, OdpsType.TIMESTAMP_NTZ);
735+
outputFormatter = getDateTimeFormatter(outputPattern, ZoneId.of("UTC"), OdpsType.TIMESTAMP_NTZ);
736736
}
737737
String parsePattern = config.timestampNtzParseFormat;
738738
if (parsePattern != null) {
739-
parseFormatter = getDateTimeFormatter(outputPattern, null, OdpsType.TIMESTAMP_NTZ);
739+
parseFormatter = getDateTimeFormatter(outputPattern, ZoneId.of("UTC"), OdpsType.TIMESTAMP_NTZ);
740740
}
741741
}
742742

@@ -747,10 +747,8 @@ public String format(Object object, TypeInfo typeInfo, OdpsRecordConverter conve
747747
Instant i = (Instant) object;
748748
formattedStr = i.atZone(zoneId).format(outputFormatter);
749749
} else if (object instanceof Timestamp) {
750-
Timestamp timestamp = (Timestamp) object;
751-
formattedStr =
752-
timestamp.getNanos() == 0 ? timestamp.toString().substring(0, 19)
753-
: timestamp.toString();
750+
Instant i = ((Timestamp) object).toInstant();
751+
formattedStr = i.atZone(zoneId).format(outputFormatter);
754752
} else if (object instanceof LocalDateTime) {
755753
LocalDateTime localDateTime = (LocalDateTime) object;
756754
formattedStr = localDateTime.format(outputFormatter);
@@ -872,12 +870,18 @@ private static DateTimeFormatter getDateTimeFormatter(String pattern, ZoneId zon
872870
}
873871
}
874872

875-
private static SimpleDateFormat getLegacyDateTimeFormatter(String pattern, OdpsType odpsType) {
873+
private static SimpleDateFormat getLegacyDateTimeFormatter(String pattern, ZoneId zoneId,
874+
OdpsType odpsType) {
876875
try {
877876
pattern = pattern.replace("u", "y");
878-
return new SimpleDateFormat(pattern);
877+
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
878+
if (zoneId != null) {
879+
simpleDateFormat.setTimeZone(TimeZone.getTimeZone(zoneId));
880+
}
881+
return simpleDateFormat;
879882
} catch (Exception e) {
880-
throw new IllegalArgumentException("DateTime format for " + odpsType + " illegal: " + pattern);
883+
throw new IllegalArgumentException(
884+
"DateTime format for " + odpsType + " illegal: " + pattern);
881885
}
882886
}
883887

odps-sdk/odps-sdk-core/src/main/java/com/aliyun/odps/task/SQLTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ public static Instance run(Odps odps, String project, String sql,
700700
*/
701701
public static Instance run(Odps odps, String project, String sql,
702702
String taskName, Map<String, String> hints,
703-
Map<String, String> aliases, int priority) throws OdpsException {
703+
Map<String, String> aliases, Integer priority) throws OdpsException {
704704
return run(odps, project, sql, taskName, hints, aliases, priority, "sql");
705705
}
706706

0 commit comments

Comments
 (0)