@@ -36,7 +36,6 @@ import com.amazon.ionelement.api.loadSingleElement
36
36
import org.antlr.v4.runtime.ParserRuleContext
37
37
import org.antlr.v4.runtime.Token
38
38
import org.antlr.v4.runtime.tree.TerminalNode
39
- import org.partiql.ast.Identifier
40
39
import org.partiql.errors.ErrorCode
41
40
import org.partiql.errors.Property
42
41
import org.partiql.errors.PropertyValueMap
@@ -118,7 +117,7 @@ import java.time.format.DateTimeParseException
118
117
*/
119
118
internal class PartiQLPigVisitor (
120
119
val customTypes : List <CustomType > = listOf(),
121
- private val parameterIndexes : Map <Int , Int > = mapOf()
120
+ private val parameterIndexes : Map <Int , Int > = mapOf(),
122
121
) :
123
122
PartiQLBaseVisitor <PartiqlAst .PartiqlAstNode >() {
124
123
@@ -648,19 +647,22 @@ internal class PartiQLPigVisitor(
648
647
excludeTupleAttr(identifier(attr, caseSensitivity))
649
648
}
650
649
651
- override fun visitExcludeExprCollectionIndex (ctx : PartiQLParser .ExcludeExprCollectionIndexContext ) = PartiqlAst .build {
652
- val index = ctx.index.text.toInteger().toLong()
653
- excludeCollectionIndex(index)
654
- }
650
+ override fun visitExcludeExprCollectionIndex (ctx : PartiQLParser .ExcludeExprCollectionIndexContext ) =
651
+ PartiqlAst .build {
652
+ val index = ctx.index.text.toInteger().toLong()
653
+ excludeCollectionIndex(index)
654
+ }
655
655
656
- override fun visitExcludeExprCollectionAttr (ctx : PartiQLParser .ExcludeExprCollectionAttrContext ) = PartiqlAst .build {
657
- val attr = ctx.attr.getStringValue()
658
- excludeTupleAttr(identifier(attr, caseSensitive()))
659
- }
656
+ override fun visitExcludeExprCollectionAttr (ctx : PartiQLParser .ExcludeExprCollectionAttrContext ) =
657
+ PartiqlAst .build {
658
+ val attr = ctx.attr.getStringValue()
659
+ excludeTupleAttr(identifier(attr, caseSensitive()))
660
+ }
660
661
661
- override fun visitExcludeExprCollectionWildcard (ctx : PartiQLParser .ExcludeExprCollectionWildcardContext ) = PartiqlAst .build {
662
- excludeCollectionWildcard()
663
- }
662
+ override fun visitExcludeExprCollectionWildcard (ctx : PartiQLParser .ExcludeExprCollectionWildcardContext ) =
663
+ PartiqlAst .build {
664
+ excludeCollectionWildcard()
665
+ }
664
666
665
667
override fun visitExcludeExprTupleWildcard (ctx : PartiQLParser .ExcludeExprTupleWildcardContext ) = PartiqlAst .build {
666
668
excludeTupleWildcard()
@@ -1292,17 +1294,20 @@ internal class PartiQLPigVisitor(
1292
1294
canLosslessCast(expr, type, metas)
1293
1295
}
1294
1296
1295
- override fun visitFunctionCallIdent (ctx : PartiQLParser .FunctionCallIdentContext ) = PartiqlAst .build {
1296
- val name = ctx.name.getString().lowercase()
1297
- val args = ctx.expr().map { visitExpr(it) }
1298
- val metas = ctx.name.getSourceMetaContainer()
1299
- call(name, args = args, metas = metas)
1300
- }
1301
-
1302
- override fun visitFunctionCallReserved (ctx : PartiQLParser .FunctionCallReservedContext ) = PartiqlAst .build {
1303
- val name = ctx.name.text.lowercase()
1297
+ override fun visitFunctionCall (ctx : PartiQLParser .FunctionCallContext ) = PartiqlAst .build {
1298
+ val name = when (val nameCtx = ctx.functionName()) {
1299
+ is PartiQLParser .FunctionNameReservedContext -> {
1300
+ if (nameCtx.qualifier.isNotEmpty()) error(" Legacy AST does not support qualified function names" )
1301
+ nameCtx.name.text.lowercase()
1302
+ }
1303
+ is PartiQLParser .FunctionNameSymbolContext -> {
1304
+ if (nameCtx.qualifier.isNotEmpty()) error(" Legacy AST does not support qualified function names" )
1305
+ nameCtx.name.getString().lowercase()
1306
+ }
1307
+ else -> error(" Expected context FunctionNameReserved or FunctionNameSymbol" )
1308
+ }
1304
1309
val args = ctx.expr().map { visitExpr(it) }
1305
- val metas = ctx.name .getSourceMetaContainer()
1310
+ val metas = ctx.start .getSourceMetaContainer()
1306
1311
call(name, args = args, metas = metas)
1307
1312
}
1308
1313
@@ -1693,7 +1698,7 @@ internal class PartiQLPigVisitor(
1693
1698
lhs : ParserRuleContext ? ,
1694
1699
rhs : ParserRuleContext ? ,
1695
1700
op : Token ? ,
1696
- parent : ParserRuleContext ? = null
1701
+ parent : ParserRuleContext ? = null,
1697
1702
) = PartiqlAst .build {
1698
1703
if (parent != null ) return @build visit(parent) as PartiqlAst .Expr
1699
1704
val args = listOf (lhs!! , rhs!! ).map { visit(it) as PartiqlAst .Expr }
@@ -1847,7 +1852,7 @@ internal class PartiQLPigVisitor(
1847
1852
withTimeZone : Boolean ,
1848
1853
precision : Long ,
1849
1854
stringNode : TerminalNode ,
1850
- timeNode : TerminalNode
1855
+ timeNode : TerminalNode ,
1851
1856
) = PartiqlAst .build {
1852
1857
val time: LocalTime
1853
1858
val formatter = when (withTimeZone) {
@@ -1871,7 +1876,7 @@ internal class PartiQLPigVisitor(
1871
1876
1872
1877
private fun getTimestampStringAndPrecision (
1873
1878
stringNode : TerminalNode ,
1874
- integerNode : TerminalNode ?
1879
+ integerNode : TerminalNode ? ,
1875
1880
): Pair <String , Long ?> {
1876
1881
val timestampString = stringNode.getStringValue()
1877
1882
val precision = when (integerNode) {
@@ -1890,7 +1895,7 @@ internal class PartiQLPigVisitor(
1890
1895
private fun getTimestampDynamic (
1891
1896
timestampString : String ,
1892
1897
precision : Long? ,
1893
- node : TerminalNode
1898
+ node : TerminalNode ,
1894
1899
) = PartiqlAst .build {
1895
1900
val timestamp =
1896
1901
try {
@@ -1901,17 +1906,22 @@ internal class PartiQLPigVisitor(
1901
1906
val timeZone = timestamp.timeZone?.let { getTimeZone(it) }
1902
1907
timestamp(
1903
1908
timestampValue(
1904
- timestamp.year.toLong(), timestamp.month.toLong(), timestamp.day.toLong(),
1905
- timestamp.hour.toLong(), timestamp.minute.toLong(), ionDecimal(Decimal .valueOf(timestamp.decimalSecond)),
1906
- timeZone, precision
1909
+ timestamp.year.toLong(),
1910
+ timestamp.month.toLong(),
1911
+ timestamp.day.toLong(),
1912
+ timestamp.hour.toLong(),
1913
+ timestamp.minute.toLong(),
1914
+ ionDecimal(Decimal .valueOf(timestamp.decimalSecond)),
1915
+ timeZone,
1916
+ precision
1907
1917
)
1908
1918
)
1909
1919
}
1910
1920
1911
1921
private fun getTimestampWithTimezone (
1912
1922
timestampString : String ,
1913
1923
precision : Long? ,
1914
- node : TerminalNode
1924
+ node : TerminalNode ,
1915
1925
) = PartiqlAst .build {
1916
1926
val timestamp = try {
1917
1927
DateTimeUtils .parseTimestamp(timestampString)
@@ -1926,9 +1936,14 @@ internal class PartiQLPigVisitor(
1926
1936
val timeZone = timestamp.timeZone?.let { getTimeZone(it) }
1927
1937
timestamp(
1928
1938
timestampValue(
1929
- timestamp.year.toLong(), timestamp.month.toLong(), timestamp.day.toLong(),
1930
- timestamp.hour.toLong(), timestamp.minute.toLong(), ionDecimal(Decimal .valueOf(timestamp.decimalSecond)),
1931
- timeZone, precision
1939
+ timestamp.year.toLong(),
1940
+ timestamp.month.toLong(),
1941
+ timestamp.day.toLong(),
1942
+ timestamp.hour.toLong(),
1943
+ timestamp.minute.toLong(),
1944
+ ionDecimal(Decimal .valueOf(timestamp.decimalSecond)),
1945
+ timeZone,
1946
+ precision
1932
1947
)
1933
1948
)
1934
1949
}
@@ -2124,13 +2139,13 @@ internal class PartiQLPigVisitor(
2124
2139
msg : String ,
2125
2140
code : ErrorCode ,
2126
2141
ctx : PropertyValueMap = PropertyValueMap (),
2127
- cause : Throwable ? = null
2142
+ cause : Throwable ? = null,
2128
2143
) = this .error(msg, code, ctx, cause)
2129
2144
2130
2145
private fun Token?.err (
2131
2146
msg : String ,
2132
2147
code : ErrorCode ,
2133
2148
ctx : PropertyValueMap = PropertyValueMap (),
2134
- cause : Throwable ? = null
2149
+ cause : Throwable ? = null,
2135
2150
) = this .error(msg, code, ctx, cause)
2136
2151
}
0 commit comments