Skip to content

Commit 4ed9b52

Browse files
committed
Revert "Preserve case for RowType's field name and JSON content when CAST"
This reverts commit d5a31b3.
1 parent 6eba1f7 commit 4ed9b52

4 files changed

Lines changed: 17 additions & 57 deletions

File tree

‎presto-common/src/main/java/com/facebook/presto/common/type/RowType.java‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,6 @@ public static Field field(Type type)
8383
return new Field(Optional.empty(), type);
8484
}
8585

86-
public static Field field(String name, Type type, boolean delimited)
87-
{
88-
return new Field(Optional.of(name), type, delimited);
89-
}
90-
9186
private static TypeSignature makeSignature(List<Field> fields)
9287
{
9388
int size = fields.size();

‎presto-main/src/main/java/com/facebook/presto/util/JsonUtil.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import java.util.Arrays;
5555
import java.util.HashMap;
5656
import java.util.List;
57+
import java.util.Locale;
5758
import java.util.Map;
5859
import java.util.Optional;
5960
import java.util.TreeMap;
@@ -1323,7 +1324,7 @@ public static void parseJsonToSingleRowBlock(
13231324
if (parser.currentToken() != FIELD_NAME) {
13241325
throw new JsonCastException(format("Expected a json field name, but got %s", parser.getText()));
13251326
}
1326-
String fieldName = parser.getText();
1327+
String fieldName = parser.getText().toLowerCase(Locale.ENGLISH);
13271328
Integer fieldIndex = fieldNameToIndex.get().get(fieldName);
13281329
parser.nextToken();
13291330
if (fieldIndex != null) {

‎presto-main/src/test/java/com/facebook/presto/type/TestRowOperators.java‎

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.facebook.presto.common.type.RowType;
2020
import com.facebook.presto.common.type.StandardTypes;
2121
import com.facebook.presto.common.type.Type;
22-
import com.facebook.presto.common.type.VarcharType;
2322
import com.facebook.presto.operator.scalar.AbstractTestFunctions;
2423
import com.facebook.presto.operator.scalar.FunctionAssertions;
2524
import com.facebook.presto.spi.StandardErrorCode;
@@ -409,35 +408,35 @@ public void testJsonToRow()
409408
"\"array2\": [1, 2, null, 3], " +
410409
"\"array1\": [], " +
411410
"\"array3\": null, " +
412-
"\"map3\": {\"a\": 1, \"b\": 2, \"none\": null, \"Three\": 3}, " +
411+
"\"map3\": {\"a\": 1, \"b\": 2, \"none\": null, \"three\": 3}, " +
413412
"\"map1\": {}, " +
414413
"\"map2\": null, " +
415414
"\"rowAsJsonArray1\": [1, 2, null, 3], " +
416415
"\"rowAsJsonArray2\": null, " +
417-
"\"rowAsJsonObject2\": {\"a\": 1, \"b\": 2, \"none\": null, \"Three\": 3}, " +
416+
"\"rowAsJsonObject2\": {\"a\": 1, \"b\": 2, \"none\": null, \"three\": 3}, " +
418417
"\"rowAsJsonObject1\": null}' " +
419-
"AS ROW(array1 array<BIGINT>, array2 ARRAY<bigint>, array3 ARRAY<BIGINT>, " +
420-
"map1 MAP<VARCHAR, BIGINT>, map2 map<varchar, BIGINT>, map3 MAP<VARCHAR, BIGINT>, " +
421-
"\"rowAsJsonArray1\" row(BIGINT, bigint, BIGINT, BIGINT), \"rowAsJsonArray2\" ROW(BIGINT)," +
422-
"\"rowAsJsonObject1\" ROW(nothing BIGINT), \"rowAsJsonObject2\" ROW(a BIGINT, b BIGINT, \"Three\" BIGINT, none BIGINT)))",
418+
"AS ROW(array1 ARRAY<BIGINT>, array2 ARRAY<BIGINT>, array3 ARRAY<BIGINT>, " +
419+
"map1 MAP<VARCHAR, BIGINT>, map2 MAP<VARCHAR, BIGINT>, map3 MAP<VARCHAR, BIGINT>, " +
420+
"rowAsJsonArray1 ROW(BIGINT, BIGINT, BIGINT, BIGINT), rowAsJsonArray2 ROW(BIGINT)," +
421+
"rowAsJsonObject1 ROW(nothing BIGINT), rowAsJsonObject2 ROW(a BIGINT, b BIGINT, three BIGINT, none BIGINT)))",
423422
RowType.from(ImmutableList.of(
424423
RowType.field("array1", new ArrayType(BIGINT)),
425424
RowType.field("array2", new ArrayType(BIGINT)),
426425
RowType.field("array3", new ArrayType(BIGINT)),
427426
RowType.field("map1", mapType(VARCHAR, BIGINT)),
428427
RowType.field("map2", mapType(VARCHAR, BIGINT)),
429428
RowType.field("map3", mapType(VARCHAR, BIGINT)),
430-
RowType.field("rowAsJsonArray1", RowType.anonymous(ImmutableList.of(BIGINT, BIGINT, BIGINT, BIGINT)), true),
431-
RowType.field("rowAsJsonArray2", RowType.anonymous(ImmutableList.of(BIGINT)), true),
432-
RowType.field("rowAsJsonObject1", RowType.from(ImmutableList.of(RowType.field("nothing", BIGINT))), true),
433-
RowType.field("rowAsJsonObject2", RowType.from(ImmutableList.of(
429+
RowType.field("rowasjsonarray1", RowType.anonymous(ImmutableList.of(BIGINT, BIGINT, BIGINT, BIGINT))),
430+
RowType.field("rowasjsonarray2", RowType.anonymous(ImmutableList.of(BIGINT))),
431+
RowType.field("rowasjsonobject1", RowType.from(ImmutableList.of(RowType.field("nothing", BIGINT)))),
432+
RowType.field("rowasjsonobject2", RowType.from(ImmutableList.of(
434433
RowType.field("a", BIGINT),
435434
RowType.field("b", BIGINT),
436-
RowType.field("Three", BIGINT, true),
437-
RowType.field("none", BIGINT))), true))),
435+
RowType.field("three", BIGINT),
436+
RowType.field("none", BIGINT)))))),
438437
asList(
439438
emptyList(), asList(1L, 2L, null, 3L), null,
440-
ImmutableMap.of(), null, asMap(ImmutableList.of("a", "b", "none", "Three"), asList(1L, 2L, null, 3L)),
439+
ImmutableMap.of(), null, asMap(ImmutableList.of("a", "b", "none", "three"), asList(1L, 2L, null, 3L)),
441440
asList(1L, 2L, null, 3L), null,
442441
null, asList(1L, 2L, 3L, null)));
443442

@@ -526,14 +525,6 @@ public void testRowCast()
526525
RowType.field("d", VARCHAR),
527526
RowType.field("e", new ArrayType(BIGINT)))),
528527
asList(2L, 1.5, true, "abc", ImmutableList.of(1L, 2L)));
529-
530-
assertFunction(
531-
"MAP(ARRAY['myFirstRow', 'mySecondRow'], ARRAY[cast(row('row1FieldValue1', 'row1FieldValue2') as row(\"firstField\" varchar, \"secondField\" varchar)), cast(row('row2FieldValue1', 'row2FieldValue2') as row(\"firstField\" varchar, \"secondField\" varchar))])",
532-
mapType(VarcharType.createVarcharType(11), RowType.from(ImmutableList.of(
533-
RowType.field("firstField", VARCHAR, true),
534-
RowType.field("secondField", VARCHAR, true)))),
535-
ImmutableMap.of("myFirstRow", asList("row1FieldValue1", "row1FieldValue2"),
536-
"mySecondRow", asList("row2FieldValue1", "row2FieldValue2")));
537528
}
538529

539530
@Test

‎presto-parser/src/main/java/com/facebook/presto/sql/tree/Cast.java‎

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Objects;
2020
import java.util.Optional;
2121

22+
import static java.util.Locale.ENGLISH;
2223
import static java.util.Objects.requireNonNull;
2324

2425
public final class Cast
@@ -66,7 +67,7 @@ public Cast(Optional<NodeLocation> location, Expression expression, String type,
6667
requireNonNull(type, "type is null");
6768

6869
this.expression = expression;
69-
this.type = transformCase(type);
70+
this.type = type.toLowerCase(ENGLISH);
7071
this.safe = safe;
7172
this.typeOnly = typeOnly;
7273
}
@@ -91,34 +92,6 @@ public boolean isTypeOnly()
9192
return typeOnly;
9293
}
9394

94-
/**
95-
* We uniformly change the whole type string to lower case,
96-
* except field names which are enclosed in double quotation marks
97-
* */
98-
private static String transformCase(String input)
99-
{
100-
if (input == null) {
101-
return null;
102-
}
103-
104-
StringBuilder sb = new StringBuilder();
105-
boolean insideQuotes = false;
106-
for (int i = 0, l = input.length(); i < l; i++) {
107-
char ch = input.charAt(i);
108-
if (ch == '"') {
109-
insideQuotes = !insideQuotes;
110-
}
111-
112-
if (insideQuotes) {
113-
sb.append(ch);
114-
}
115-
else {
116-
sb.append(Character.toLowerCase(ch));
117-
}
118-
}
119-
return sb.toString();
120-
}
121-
12295
@Override
12396
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
12497
{

0 commit comments

Comments
 (0)