Skip to content

Commit ee7bd81

Browse files
committed
prepare for 0.51.6-public
1 parent 5a0e34e commit ee7bd81

File tree

9 files changed

+138
-21
lines changed

9 files changed

+138
-21
lines changed

odps-sdk/odps-sdk-commons/src/main/java/com/aliyun/odps/TableSchema.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ public List<Column> getColumns() {
171171
return (List<Column>) columns.clone();
172172
}
173173

174+
@Deprecated
175+
public void setPartitionColumns(ArrayList<Column> partitionColumns) {
176+
setPartitionColumns((List<Column>)partitionColumns);
177+
}
178+
174179
public void setPartitionColumns(List<Column> partitionColumns) {
175180
this.partitionNameMap.clear();
176181
this.partitionColumns.clear();

odps-sdk/odps-sdk-commons/src/main/java/com/aliyun/odps/type/ArrayTypeInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
*
88
* Created by zhenhong.gzh on 16/7/8.
99
*/
10-
public interface ArrayTypeInfo extends TypeInfo {
10+
public interface ArrayTypeInfo extends NestedTypeInfo {
1111
TypeInfo getElementTypeInfo();
1212
}

odps-sdk/odps-sdk-commons/src/main/java/com/aliyun/odps/type/MapTypeInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Created by zhenhong.gzh on 16/7/8.
99
*/
10-
public interface MapTypeInfo extends TypeInfo {
10+
public interface MapTypeInfo extends NestedTypeInfo {
1111
TypeInfo getKeyTypeInfo();
1212
TypeInfo getValueTypeInfo();
1313
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.aliyun.odps.type;
2+
3+
import com.aliyun.odps.OdpsType;
4+
5+
/**
6+
* @author dingxin (zhangdingxin.zdx@alibaba-inc.com)
7+
*/
8+
public interface NestedTypeInfo extends TypeInfo {
9+
/**
10+
* 此方法会将struct类型中,列字段进行转义。适用于拼装 SQL 场景
11+
* 当 quote = false 时,此方法与 getTypeName() 相同
12+
*/
13+
String getTypeName(boolean quote);
14+
}

odps-sdk/odps-sdk-commons/src/main/java/com/aliyun/odps/type/SimpleArrayTypeInfo.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ class SimpleArrayTypeInfo implements ArrayTypeInfo {
2828
valueType = typeInfo;
2929
}
3030

31-
@Override
32-
public String getTypeName() {
33-
return getOdpsType().name() + "<" + valueType.getTypeName() + ">";
34-
}
35-
3631
/**
3732
* 获取 Array 里元素类型信息
3833
*
@@ -69,4 +64,16 @@ public boolean equals(Object o) {
6964
public int hashCode() {
7065
return Objects.hash(valueType);
7166
}
67+
68+
@Override
69+
public String getTypeName() {
70+
return getTypeName(false);
71+
}
72+
@Override
73+
public String getTypeName(boolean quote) {
74+
if (quote && valueType instanceof SimpleStructTypeInfo) {
75+
return getOdpsType().name() + "<" + ((SimpleStructTypeInfo) valueType).getTypeName(true) + ">";
76+
}
77+
return getOdpsType().name() + "<" + valueType.getTypeName() + ">";
78+
}
7279
}

odps-sdk/odps-sdk-commons/src/main/java/com/aliyun/odps/type/SimpleMapTypeInfo.java

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ class SimpleMapTypeInfo implements MapTypeInfo {
3232
this.valueType = valueType;
3333
}
3434

35-
@Override
36-
public String getTypeName() {
37-
return getOdpsType().name() + "<" + keyType.getTypeName() + "," + valueType.getTypeName() + ">";
38-
}
39-
4035
/**
4136
* 获取键的类型
4237
*
@@ -83,4 +78,36 @@ public boolean equals(Object o) {
8378
public int hashCode() {
8479
return Objects.hash(keyType, valueType);
8580
}
81+
82+
@Override
83+
public String getTypeName() {
84+
return getTypeName(false);
85+
}
86+
87+
@Override
88+
public String getTypeName(boolean quote) {
89+
String baseType = getOdpsType().name();
90+
91+
if (!quote) {
92+
return String.format("%s<%s,%s>",
93+
baseType,
94+
keyType.getTypeName(),
95+
valueType.getTypeName()
96+
);
97+
}
98+
99+
StringBuilder sb = new StringBuilder(baseType).append("<");
100+
appendNestedType(sb, keyType);
101+
sb.append(",");
102+
appendNestedType(sb, valueType);
103+
return sb.append(">").toString();
104+
}
105+
106+
private void appendNestedType(StringBuilder sb, TypeInfo type) {
107+
if (type instanceof NestedTypeInfo) {
108+
sb.append(((NestedTypeInfo) type).getTypeName(true));
109+
} else {
110+
sb.append(type.getTypeName());
111+
}
112+
}
86113
}

odps-sdk/odps-sdk-commons/src/main/java/com/aliyun/odps/type/StructTypeInfo.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,8 @@
99
*
1010
* Created by zhenhong.gzh on 16/7/8.
1111
*/
12-
public interface StructTypeInfo extends TypeInfo {
12+
public interface StructTypeInfo extends NestedTypeInfo {
1313
List<String> getFieldNames();
1414
List<TypeInfo> getFieldTypeInfos();
1515
int getFieldCount();
16-
17-
/**
18-
* 此方法会将struct类型中,列字段进行转义。适用于拼装 SQL 场景
19-
* 当 quote = false 时,此方法与 getTypeName() 相同
20-
*/
21-
String getTypeName(boolean quote);
2216
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.aliyun.odps.type;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import org.junit.Assert;
7+
import org.junit.Test;
8+
9+
/**
10+
* @author dingxin (zhangdingxin.zdx@alibaba-inc.com)
11+
*/
12+
public class NestedTypeQuoteTest {
13+
14+
private static StructTypeInfo nestedTypeInfo;
15+
16+
static {
17+
List<String> names = new ArrayList<>();
18+
names.add("end");
19+
names.add("start");
20+
List<TypeInfo> typeInfos = new ArrayList<>();
21+
typeInfos.add(TypeInfoFactory.STRING);
22+
typeInfos.add(TypeInfoFactory.BIGINT);
23+
24+
nestedTypeInfo = TypeInfoFactory.getStructTypeInfo(names, typeInfos);
25+
}
26+
27+
@Test
28+
public void testBasic() {
29+
String typeWithNoQuote = nestedTypeInfo.getTypeName();
30+
Assert.assertEquals("STRUCT<end:STRING,start:BIGINT>", typeWithNoQuote);
31+
String typeWithQuote = nestedTypeInfo.getTypeName(true);
32+
Assert.assertEquals("STRUCT<`end`:STRING,`start`:BIGINT>", typeWithQuote);
33+
}
34+
35+
@Test
36+
public void testArray() {
37+
ArrayTypeInfo arrayTypeInfo = TypeInfoFactory.getArrayTypeInfo(nestedTypeInfo);
38+
String typeName = arrayTypeInfo.getTypeName();
39+
Assert.assertEquals("ARRAY<STRUCT<end:STRING,start:BIGINT>>", typeName);
40+
String typeNameWithQuote = arrayTypeInfo.getTypeName(true);
41+
Assert.assertEquals("ARRAY<STRUCT<`end`:STRING,`start`:BIGINT>>", typeNameWithQuote);
42+
}
43+
44+
@Test
45+
public void testMap() {
46+
MapTypeInfo mapTypeInfo = TypeInfoFactory.getMapTypeInfo(nestedTypeInfo, nestedTypeInfo);
47+
String typeName = mapTypeInfo.getTypeName();
48+
Assert.assertEquals("MAP<STRUCT<end:STRING,start:BIGINT>,STRUCT<end:STRING,start:BIGINT>>", typeName);
49+
String typeNameWithQuote = mapTypeInfo.getTypeName(true);
50+
Assert.assertEquals("MAP<STRUCT<`end`:STRING,`start`:BIGINT>,STRUCT<`end`:STRING,`start`:BIGINT>>", typeNameWithQuote);
51+
}
52+
53+
@Test
54+
public void testStruct() {
55+
List<String> names = new ArrayList<>();
56+
names.add("end");
57+
names.add("start");
58+
List<TypeInfo> typeInfos = new ArrayList<>();
59+
typeInfos.add(nestedTypeInfo);
60+
typeInfos.add(nestedTypeInfo);
61+
StructTypeInfo structTypeInfo = TypeInfoFactory.getStructTypeInfo(names, typeInfos);
62+
String typeName = structTypeInfo.getTypeName();
63+
Assert.assertEquals("STRUCT<end:STRUCT<end:STRING,start:BIGINT>,start:STRUCT<end:STRING,start:BIGINT>>", typeName);
64+
65+
String typeNameWithQuote = structTypeInfo.getTypeName(true);
66+
Assert.assertEquals("STRUCT<`end`:STRUCT<`end`:STRING,`start`:BIGINT>,`start`:STRUCT<`end`:STRING,`start`:BIGINT>>", typeNameWithQuote);
67+
}
68+
69+
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.aliyun.odps.simpleframework.xml.convert.Convert;
4040
import com.aliyun.odps.table.utils.Preconditions;
4141
import com.aliyun.odps.task.SQLTask;
42+
import com.aliyun.odps.type.NestedTypeInfo;
4243
import com.aliyun.odps.type.StructTypeInfo;
4344
import com.aliyun.odps.type.TypeInfo;
4445
import com.aliyun.odps.type.TypeInfoFactory;
@@ -1413,8 +1414,8 @@ private String generateCreateTableSql() {
14131414
}
14141415

14151416
private String getTypeName(TypeInfo typeInfo) {
1416-
if (typeInfo instanceof StructTypeInfo) {
1417-
return ((StructTypeInfo) typeInfo).getTypeName(true);
1417+
if (typeInfo instanceof NestedTypeInfo) {
1418+
return ((NestedTypeInfo) typeInfo).getTypeName(true);
14181419
}
14191420
return typeInfo.getTypeName();
14201421
}

0 commit comments

Comments
 (0)