Skip to content

Commit fc3f9e6

Browse files
committed
BREAKING! Make IntervalDataType use IntervalUnit
Replace fieldsKw and precision properties with unit.
1 parent 2ca2efe commit fc3f9e6

File tree

3 files changed

+5
-14
lines changed

3 files changed

+5
-14
lines changed

src/cst/DataType.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { BaseNode, Empty, Keyword } from "./Base";
22
import { ColumnConstraint } from "./Constraint";
33
import { ColumnDefinition } from "./CreateTable";
44
import { EntityName, Expr, Identifier, ListExpr, ParenExpr } from "./Expr";
5-
import { NumberLiteral } from "./Literal";
5+
import { IntervalUnit, IntervalUnitRange, NumberLiteral } from "./Literal";
66

77
export type AllDataTypeNodes =
88
| DataTypeName
@@ -74,14 +74,7 @@ export interface TimeDataType extends BaseNode {
7474
export interface IntervalDataType extends BaseNode {
7575
type: "interval_data_type";
7676
intervalKw: Keyword<"INTERVAL">;
77-
fieldsKw?:
78-
| Keyword<"YEAR" | "MONTH" | "DAY" | "HOUR" | "MINUTE" | "SECOND">
79-
| [
80-
Keyword<"YEAR" | "MONTH" | "DAY" | "HOUR" | "MINUTE" | "SECOND">,
81-
Keyword<"TO">,
82-
Keyword<"YEAR" | "MONTH" | "DAY" | "HOUR" | "MINUTE" | "SECOND">
83-
];
84-
precision?: ParenExpr<Expr>;
77+
unit?: IntervalUnit | IntervalUnitRange;
8578
}
8679

8780
// BigQuery

src/parser.pegjs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7075,12 +7075,11 @@ time_data_type
70757075
}
70767076

70777077
interval_data_type
7078-
= kw:INTERVAL fieldsKw:(__ interval_unit_kw __ TO __ interval_unit_kw / __ interval_unit_kw)? precision:(__ paren$expr)? {
7078+
= kw:INTERVAL unit:(__ (interval_unit_range / interval_unit))? {
70797079
return loc({
70807080
type: "interval_data_type",
70817081
intervalKw: read(kw),
7082-
fieldsKw: read(fieldsKw),
7083-
precision: read(precision),
7082+
unit: read(unit),
70847083
});
70857084
}
70867085

src/showNode/data_type.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ export const dataTypeMap: FullTransformMap<string, AllDataTypeNodes> = {
1010
array_bounds: (node) => show(["[", node.bounds, "]"]),
1111
time_data_type: (node) =>
1212
show([node.timeKw, node.precision, node.timeZoneKw]),
13-
interval_data_type: (node) =>
14-
show([node.intervalKw, node.fieldsKw, node.precision]),
13+
interval_data_type: (node) => show([node.intervalKw, node.unit]),
1514
generic_type_params: (node) => show(["<", node.params, ">"]),
1615
array_type_param: (node) => show([node.dataType, node.constraints]),
1716
struct_type_param: (node) =>

0 commit comments

Comments
 (0)