Skip to content

Commit

Permalink
Remove support for DataType alias
Browse files Browse the repository at this point in the history
Signed-off-by: Heng Qian <[email protected]>
  • Loading branch information
qianheng-aws committed Nov 28, 2024
1 parent 8fbc5d6 commit bf31887
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 42 deletions.
4 changes: 2 additions & 2 deletions docs/ppl-lang/PPL-Example-Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,8 @@ _- **Limitation: another command usage of (relation) subquery is in `appendcols`
#### **Cast**
[See additional command details](functions/ppl-conversion.md)
- `source = table | eval int_to_string = cast(1 as string) | fields int_to_string`
- `source = table | eval int_to_string = cast(int_col as string) | fields int_col, int_to_string`
- `source = table | eval int_to_string = cast(int_col as string), string_to_int = cast(string_col as integer) | fields int_to_string, string_to_int`
- `source = table | eval cdate = CAST('2012-08-07' as date), ctime = cast('2012-08-07T08:07:06' as timestamp) | fields cdate, ctime`
- `source = table | eval chained_cast = cast(cast("true" as boolean) as int) | fields chained_cast`
- `source = table | eval chained_cast = cast(cast("true" as boolean) as integer) | fields chained_cast`

---
7 changes: 2 additions & 5 deletions docs/ppl-lang/functions/ppl-conversion.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
| TIME | Note1 | N/A | N/A | N/A | N/A |
+------------+--------+--------+---------+-------------+--------+
```
- `NUMBER` includes `INTEGER` (alias `INT`), `LONG`, `FLOAT`, `DOUBLE`.

- `BOOLEAN` has the alias `BOOL`.

- `NUMBER` includes `INTEGER`, `LONG`, `FLOAT`, `DOUBLE`.

Cast to **string** example:

Expand All @@ -40,7 +37,7 @@ Cast to **string** example:

Cast to **number** example:

os> source=people | eval `cbool` = CAST(true as int), `cstring` = CAST('1' as int) | fields `cbool`, `cstring`
os> source=people | eval `cbool` = CAST(true as integer), `cstring` = CAST('1' as integer) | fields `cbool`, `cstring`
fetched rows / total rows = 1/1
+---------+-----------+
| cbool | cstring |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class FlintSparkPPLCastITSuite
test("test cast string to compatible data types") {
val frame = sql(s"""
| source=$testTable | eval
| id_int = cast(cast(id as string) as int),
| id_int = cast(cast(id as string) as integer),
| cast_true = cast("True" as boolean),
| cast_false = cast("false" as boolean),
| cast_timestamp = cast("2024-11-26 23:39:06" as timestamp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ public enum DataType {
@Getter private final ExprCoreType coreType;

public static DataType fromString(String name) {
String upperName = name.toUpperCase();
// Cover some dataType alias
switch (upperName) {
case "INT":
return INTEGER;
case "BOOL":
return BOOLEAN;
default:
return valueOf(upperName);
}
return valueOf(name.toUpperCase());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,6 @@ class PPLLogicalPlanCastTestSuite
comparePlans(expectedPlan, logPlan2, false)
}

test("test cast with alias") {
val table = UnresolvedRelation(Seq("t"))
val expectedPlan = Project(
seq(UnresolvedStar(None)),
Project(
seq(UnresolvedStar(None), Alias(Cast(UnresolvedAttribute("a"), IntegerType), "a")()),
table))

val context = new CatalystPlanContext
val logPlan =
planTransformer.visit(
plan(pplParser, """source=t | eval a = cast(a as integer)"""),
context)
comparePlans(expectedPlan, logPlan, false)

// test dataType alias
val context2 = new CatalystPlanContext
val logPlan2 =
planTransformer.visit(plan(pplParser, """source=t | eval a = cast(a as int)"""), context2)
comparePlans(expectedPlan, logPlan2, false)
}

test("test cast literal") {
val table = UnresolvedRelation(Seq("t"))
val expectedPlan = Project(
Expand All @@ -84,7 +62,7 @@ class PPLLogicalPlanCastTestSuite
val context = new CatalystPlanContext
val logPlan =
planTransformer.visit(
plan(pplParser, """source=t | eval a = cast(cast("a" as INT) as STRING)"""),
plan(pplParser, """source=t | eval a = cast(cast("a" as INTEGER) as STRING)"""),
context)
comparePlans(expectedPlan, logPlan, false)
}
Expand All @@ -102,7 +80,7 @@ class PPLLogicalPlanCastTestSuite
val context = new CatalystPlanContext
val logPlan =
planTransformer.visit(
plan(pplParser, """source=t | eval a = cast(cast(a as INT) as STRING)"""),
plan(pplParser, """source=t | eval a = cast(cast(a as INTEGER) as STRING)"""),
context)
comparePlans(expectedPlan, logPlan, false)
}
Expand Down

0 comments on commit bf31887

Please sign in to comment.