From 8b3075207cea8ed6487f71824eb2a3b8f3c83ec9 Mon Sep 17 00:00:00 2001 From: John Ed Quinn Date: Wed, 16 Aug 2023 14:40:03 -0700 Subject: [PATCH] Adds syntactical support for CREATE FUNCTION --- .../src/main/resources/partiql_ast.ion | 60 +++++ partiql-parser/src/main/antlr/PartiQL.g4 | 145 +++++++++++ .../src/main/antlr/PartiQLTokens.g4 | 4 + .../parser/impl/PartiQLParserDefault.kt | 77 ++++++ .../resources/built-in-functions/README.md | 157 ++++++++++++ .../partiql-converted/ABSDECIMALP_S.sql | 5 + .../partiql-converted/ABSDOUBLEPRECISION.sql | 5 + .../partiql-converted/ABSFLOATBP.sql | 5 + .../partiql-converted/ABSINTEGER.sql | 5 + .../partiql-converted/ABSNUMERICP_S.sql | 5 + .../partiql-converted/ABSREAL.sql | 5 + .../partiql-converted/ABSSMALLINT.sql | 5 + .../partiql-converted/BIT_LENGTH1.sql | 5 + .../partiql-converted/BIT_LENGTH2.sql | 5 + .../partiql-converted/CHARACTER_LENGTH1.sql | 5 + .../partiql-converted/CHARACTER_LENGTH2.sql | 5 + .../partiql-converted/CHAR_LENGTH1.sql | 5 + .../partiql-converted/CHAR_LENGTH2.sql | 5 + .../partiql-converted/LOWER1.sql | 5 + .../partiql-converted/LOWER2.sql | 5 + .../MODDECIMALMP_DECIMALP.sql | 6 + .../MODDECIMALMP_INTEGER.sql | 6 + .../MODDECIMALMP_NUMERICP.sql | 6 + .../MODDECIMALMP_SMALLINT.sql | 6 + .../partiql-converted/MODINTEGER_DECIMALP.sql | 6 + .../partiql-converted/MODINTEGER_INTEGER.sql | 6 + .../partiql-converted/MODINTEGER_NUMERICP.sql | 6 + .../partiql-converted/MODINTEGER_SMALLINT.sql | 6 + .../MODNUMERICMP_DECIMALP.sql | 6 + .../MODNUMERICMP_INTEGER.sql | 6 + .../MODNUMERICMP_NUMERICP.sql | 6 + .../MODNUMERICMP_SMALLINT.sql | 6 + .../MODSMALLINT_DECIMALP.sql | 6 + .../partiql-converted/MODSMALLINT_INTEGER.sql | 6 + .../MODSMALLINT_NUMERICP.sql | 6 + .../MODSMALLINT_SMALLINT.sql | 6 + .../partiql-converted/OCTET_LENGTH1.sql | 5 + .../partiql-converted/OCTET_LENGTH2.sql | 5 + .../partiql-converted/POSITION1.sql | 6 + .../partiql-converted/POSITION2.sql | 6 + .../partiql-converted/POSITION3.sql | 6 + .../partiql-converted/POSITION4.sql | 6 + .../partiql-converted/SUBSTRING1.sql | 7 + .../partiql-converted/SUBSTRING2.sql | 7 + .../partiql-converted/SUBSTRING3.sql | 6 + .../partiql-converted/SUBSTRING4.sql | 6 + .../partiql-converted/UPPER1.sql | 5 + .../partiql-converted/UPPER2.sql | 5 + .../built-in-functions/sql/ABSDECIMALP_S.sql | 5 + .../sql/ABSDOUBLEPRECISION.sql | 5 + .../built-in-functions/sql/ABSFLOATBP.sql | 5 + .../built-in-functions/sql/ABSINTEGER.sql | 5 + .../built-in-functions/sql/ABSNUMERICP_S.sql | 5 + .../built-in-functions/sql/ABSREAL.sql | 5 + .../built-in-functions/sql/ABSSMALLINT.sql | 5 + .../built-in-functions/sql/BIT_LENGTH1.sql | 5 + .../built-in-functions/sql/BIT_LENGTH2.sql | 5 + .../sql/CHARACTER_LENGTH1.sql | 5 + .../sql/CHARACTER_LENGTH2.sql | 5 + .../built-in-functions/sql/CHAR_LENGTH1.sql | 5 + .../built-in-functions/sql/CHAR_LENGTH2.sql | 5 + .../built-in-functions/sql/LOWER1.sql | 5 + .../built-in-functions/sql/LOWER2.sql | 5 + .../sql/MODDECIMALMP_DECIMALP.sql | 6 + .../sql/MODDECIMALMP_INTEGER.sql | 6 + .../sql/MODDECIMALMP_NUMERICP.sql | 6 + .../sql/MODDECIMALMP_SMALLINT.sql | 6 + .../sql/MODINTEGER_DECIMALP.sql | 6 + .../sql/MODINTEGER_INTEGER.sql | 6 + .../sql/MODINTEGER_NUMERICP.sql | 6 + .../sql/MODINTEGER_SMALLINT.sql | 6 + .../sql/MODNUMERICMP_DECIMALP.sql | 6 + .../sql/MODNUMERICMP_INTEGER.sql | 6 + .../sql/MODNUMERICMP_NUMERICP.sql | 6 + .../sql/MODNUMERICMP_SMALLINT.sql | 6 + .../sql/MODSMALLINT_DECIMALP.sql | 6 + .../sql/MODSMALLINT_INTEGER.sql | 6 + .../sql/MODSMALLINT_NUMERICP.sql | 6 + .../sql/MODSMALLINT_SMALLINT.sql | 6 + .../built-in-functions/sql/OCTET_LENGTH1.sql | 5 + .../built-in-functions/sql/OCTET_LENGTH2.sql | 5 + .../built-in-functions/sql/POSITION1.sql | 6 + .../built-in-functions/sql/POSITION2.sql | 6 + .../built-in-functions/sql/POSITION3.sql | 6 + .../built-in-functions/sql/POSITION4.sql | 6 + .../built-in-functions/sql/SUBSTRING1.sql | 7 + .../built-in-functions/sql/SUBSTRING2.sql | 7 + .../built-in-functions/sql/SUBSTRING3.sql | 6 + .../built-in-functions/sql/SUBSTRING4.sql | 6 + .../built-in-functions/sql/UPPER1.sql | 5 + .../built-in-functions/sql/UPPER2.sql | 5 + .../sql/parse-failures/ABSINTERVALDAYIP.sql | 7 + .../parse-failures/ABSINTERVALDAYIP_HOUR.sql | 6 + .../ABSINTERVALDAYIP_MINUTE.sql | 6 + .../ABSINTERVALDAYIP_SECONDIS.sql | 6 + .../sql/parse-failures/ABSINTERVALHOURIP.sql | 7 + .../ABSINTERVALHOURIP_MINUTE.sql | 6 + .../ABSINTERVALHOURIP_SECONDIS.sql | 6 + .../parse-failures/ABSINTERVALMINUTEIP.sql | 6 + .../ABSINTERVALMINUTEIP_SECONDIS.sql | 6 + .../sql/parse-failures/ABSINTERVALMONTHIP.sql | 6 + .../parse-failures/ABSINTERVALSECONDIP_IS.sql | 6 + .../sql/parse-failures/ABSINTERVALYEARIP.sql | 6 + .../ABSINTERVALYEARIP_MONTH.sql | 6 + .../sql/parse-failures/BIT_LENGTH3.sql | 5 + .../sql/parse-failures/BIT_LENGTH4.sql | 6 + .../sql/parse-failures/CHARACTER_LENGTH3.sql | 6 + .../sql/parse-failures/CHARACTER_LENGTH4.sql | 6 + .../sql/parse-failures/CHAR_LENGTH3.sql | 5 + .../sql/parse-failures/CHAR_LENGTH4.sql | 6 + .../sql/parse-failures/OCTET_LENGTH3.sql | 5 + .../sql/parse-failures/OCTET_LENGTH4.sql | 5 + .../sql/parse-failures/SUBSTRING5.sql | 7 + .../sql/parse-failures/SUBSTRING6.sql | 7 + .../sql/parse-failures/SUBSTRING7.sql | 6 + .../sql/parse-failures/SUBSTRING8.sql | 6 + .../parser/impl/PartiQLParserDefaultTests.kt | 237 ++++++++++++++++++ 117 files changed, 1312 insertions(+) create mode 100644 partiql-parser/src/main/resources/built-in-functions/README.md create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSDECIMALP_S.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSDOUBLEPRECISION.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSFLOATBP.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSINTEGER.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSNUMERICP_S.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSREAL.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSSMALLINT.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/BIT_LENGTH1.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/BIT_LENGTH2.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/CHARACTER_LENGTH1.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/CHARACTER_LENGTH2.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/CHAR_LENGTH1.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/CHAR_LENGTH2.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/LOWER1.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/LOWER2.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODDECIMALMP_DECIMALP.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODDECIMALMP_INTEGER.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODDECIMALMP_NUMERICP.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODDECIMALMP_SMALLINT.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODINTEGER_DECIMALP.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODINTEGER_INTEGER.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODINTEGER_NUMERICP.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODINTEGER_SMALLINT.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODNUMERICMP_DECIMALP.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODNUMERICMP_INTEGER.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODNUMERICMP_NUMERICP.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODNUMERICMP_SMALLINT.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODSMALLINT_DECIMALP.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODSMALLINT_INTEGER.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODSMALLINT_NUMERICP.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODSMALLINT_SMALLINT.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/OCTET_LENGTH1.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/OCTET_LENGTH2.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/POSITION1.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/POSITION2.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/POSITION3.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/POSITION4.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/SUBSTRING1.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/SUBSTRING2.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/SUBSTRING3.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/SUBSTRING4.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/UPPER1.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/partiql-converted/UPPER2.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/ABSDECIMALP_S.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/ABSDOUBLEPRECISION.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/ABSFLOATBP.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/ABSINTEGER.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/ABSNUMERICP_S.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/ABSREAL.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/ABSSMALLINT.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/BIT_LENGTH1.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/BIT_LENGTH2.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/CHARACTER_LENGTH1.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/CHARACTER_LENGTH2.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/CHAR_LENGTH1.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/CHAR_LENGTH2.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/LOWER1.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/LOWER2.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/MODDECIMALMP_DECIMALP.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/MODDECIMALMP_INTEGER.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/MODDECIMALMP_NUMERICP.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/MODDECIMALMP_SMALLINT.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/MODINTEGER_DECIMALP.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/MODINTEGER_INTEGER.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/MODINTEGER_NUMERICP.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/MODINTEGER_SMALLINT.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/MODNUMERICMP_DECIMALP.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/MODNUMERICMP_INTEGER.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/MODNUMERICMP_NUMERICP.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/MODNUMERICMP_SMALLINT.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/MODSMALLINT_DECIMALP.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/MODSMALLINT_INTEGER.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/MODSMALLINT_NUMERICP.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/MODSMALLINT_SMALLINT.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/OCTET_LENGTH1.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/OCTET_LENGTH2.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/POSITION1.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/POSITION2.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/POSITION3.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/POSITION4.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/SUBSTRING1.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/SUBSTRING2.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/SUBSTRING3.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/SUBSTRING4.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/UPPER1.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/UPPER2.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALDAYIP.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALDAYIP_HOUR.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALDAYIP_MINUTE.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALDAYIP_SECONDIS.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALHOURIP.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALHOURIP_MINUTE.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALHOURIP_SECONDIS.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALMINUTEIP.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALMINUTEIP_SECONDIS.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALMONTHIP.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALSECONDIP_IS.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALYEARIP.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALYEARIP_MONTH.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/BIT_LENGTH3.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/BIT_LENGTH4.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/CHARACTER_LENGTH3.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/CHARACTER_LENGTH4.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/CHAR_LENGTH3.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/CHAR_LENGTH4.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/OCTET_LENGTH3.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/OCTET_LENGTH4.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/SUBSTRING5.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/SUBSTRING6.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/SUBSTRING7.sql create mode 100644 partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/SUBSTRING8.sql create mode 100644 partiql-parser/src/test/kotlin/org/partiql/parser/impl/PartiQLParserDefaultTests.kt diff --git a/partiql-ast/src/main/resources/partiql_ast.ion b/partiql-ast/src/main/resources/partiql_ast.ion index e4cf854f28..380f4c26fa 100644 --- a/partiql-ast/src/main/resources/partiql_ast.ion +++ b/partiql-ast/src/main/resources/partiql_ast.ion @@ -114,6 +114,33 @@ statement::[ definition: optional::table_definition, }, + // CREATE FUNCTION + create_function::{ + specification: specification, + body: routine_body, + _: [ + specification::{ + name: '.identifier.qualified', + parameters: list::[parameter_declaration], + returns: returns, + characteristics: list::[routine_characteristic], + }, + parameter_declaration::{ + name: optional::'.identifier.symbol', + type: '.type' + }, + // SQL:1999 + // ::= RETURNS [ ] + // ::= [ ] + // ::= CAST FROM + // ::= [ ] + // TODO: Eventually add other grammatical rules here + returns::{ + type: '.type' + } + ] + }, + // CREATE INDEX [] ON ( [, ]...) create_index::{ index: optional::identifier, @@ -133,6 +160,19 @@ statement::[ }, ], + // SQL:1999 + // ::= + // + // | + // ::= + // RETURN + // ::= + // + // | NULL + return::{ + value: expr + }, + // EXEC [.*] exec::{ procedure: string, @@ -149,6 +189,26 @@ statement::[ }, ], }, + + _::[ + // SQL:1999 + // ::= + // <-- nicknaming this `internal` + // | <-- nicknaming this `external` + routine_body::[ + // SQL:1999 + // (nicknamed `internal`) ::= + // Note: Semantic pass should ensure the statement is a procedure statement. + internal::{ + procedure_statement: statement + } + ], + routine_characteristic::[ + specific::{ + name: '.identifier.qualified' + } + ] + ] ] // PartiQL Type AST nodes diff --git a/partiql-parser/src/main/antlr/PartiQL.g4 b/partiql-parser/src/main/antlr/PartiQL.g4 index b7b0561bf2..1d31cfb9ff 100644 --- a/partiql-parser/src/main/antlr/PartiQL.g4 +++ b/partiql-parser/src/main/antlr/PartiQL.g4 @@ -19,8 +19,153 @@ statement | dml COLON_SEMI? EOF # QueryDml | ddl COLON_SEMI? EOF # QueryDdl | execCommand COLON_SEMI? EOF # QueryExec + | sqlInvokedRoutine # CreateRoutineStatement ; +// SQL:1999 +// ::= +sqlInvokedRoutine + : schemaRoutine + ; + +// SQL:1999 +// ::= +// +// | +schemaRoutine + : schemaFunction + ; + +// SQL:1999 +// ::= +// CREATE +schemaFunction + : CREATE sqlInvokedFunction + ; + +// SQL:1999 +// ::= +// { | } +// +sqlInvokedFunction + : + ( + functionSpecification + ) routineBody + ; + +// SQL:1999 +// ::= +// FUNCTION +// +// +// +// [ ] +functionSpecification + : FUNCTION name=symbolPrimitive // FIXME: Should be schemaQualifiedRoutineName + sqlParameterDeclarationList + returnsClause + routineCharacteristic* + ; + +// SQL:1999 +// ::= +// SPECIFIC +// | and many more... +routineCharacteristic + : SPECIFIC specificName + ; + +// SQL:1999 +// ::= +specificName + : name=symbolPrimitive // FIXME: should be ```schemaQualifiedName``` + ; + +// SQL:1999 +// ::= RETURNS [ ] +returnsClause + : RETURNS returnsDataType + ; + +// SQL:1999 +// ::= [ ] +returnsDataType + : type + ; + +// SQL:1999 +// ::= +// +// | +routineBody + : sqlRoutineBody + ; + +// SQL:1999 +// ::= +// +// [ [ { }... ] ] +// +sqlParameterDeclarationList + : PAREN_LEFT (sqlParameterDeclaration (COMMA sqlParameterDeclaration)* )? PAREN_RIGHT + ; + +// SQL:1999 +// ::= +// [ ] [ ] +// +// [ RESULT ] +sqlParameterDeclaration + : sqlParameterName? parameterType + ; + +// SQL:1999 +// ::= +sqlParameterName + : symbolPrimitive + ; + +// SQL:1999 +// ::= +// [ ] +parameterType + : type + ; + +// SQL:1999 +// ::= +sqlRoutineBody: sqlProcedureStatement; + +// SQL:1999 +// ::= +sqlProcedureStatement: sqlExecutableStatement; + +// SQL:1999 +// ::= +// +// | many more alternatives... +sqlExecutableStatement + : sqlControlStatement + ; + +// SQL:1999 +// ::= +// +// | +sqlControlStatement + : returnStatement + ; + +// SQL:1999 +// ::= +// RETURN +// ::= +// +// | NULL +returnStatement + : RETURN expr; + /** * * COMMON STRUCTURES diff --git a/partiql-parser/src/main/antlr/PartiQLTokens.g4 b/partiql-parser/src/main/antlr/PartiQLTokens.g4 index dd0f561246..c101d7d817 100644 --- a/partiql-parser/src/main/antlr/PartiQLTokens.g4 +++ b/partiql-parser/src/main/antlr/PartiQLTokens.g4 @@ -119,6 +119,7 @@ FOREIGN: 'FOREIGN'; FOUND: 'FOUND'; FROM: 'FROM'; FULL: 'FULL'; +FUNCTION: 'FUNCTION'; GET: 'GET'; GLOBAL: 'GLOBAL'; GO: 'GO'; @@ -197,6 +198,8 @@ REFERENCES: 'REFERENCES'; RELATIVE: 'RELATIVE'; REPLACE: 'REPLACE'; RESTRICT: 'RESTRICT'; +RETURN: 'RETURN'; +RETURNS: 'RETURNS'; REVOKE: 'REVOKE'; RIGHT: 'RIGHT'; ROLLBACK: 'ROLLBACK'; @@ -213,6 +216,7 @@ SIZE: 'SIZE'; SMALLINT: 'SMALLINT'; SOME: 'SOME'; SPACE: 'SPACE'; +SPECIFIC: 'SPECIFIC'; SQL: 'SQL'; SQLCODE: 'SQLCODE'; SQLERROR: 'SQLERROR'; diff --git a/partiql-parser/src/main/kotlin/org/partiql/parser/impl/PartiQLParserDefault.kt b/partiql-parser/src/main/kotlin/org/partiql/parser/impl/PartiQLParserDefault.kt index 860a711ca6..3ea1607d7d 100644 --- a/partiql-parser/src/main/kotlin/org/partiql/parser/impl/PartiQLParserDefault.kt +++ b/partiql-parser/src/main/kotlin/org/partiql/parser/impl/PartiQLParserDefault.kt @@ -508,6 +508,82 @@ internal class PartiQLParserDefault : PartiQLParser { statementExec(procedure, args) } + // FUNCTION + + override fun visitSqlInvokedRoutine(ctx: org.partiql.parser.antlr.PartiQLParser.SqlInvokedRoutineContext?): AstNode { + return super.visitSqlInvokedRoutine(ctx) + } + + override fun visitSchemaRoutine(ctx: org.partiql.parser.antlr.PartiQLParser.SchemaRoutineContext?): AstNode { + return super.visitSchemaRoutine(ctx) + } + + override fun visitSchemaFunction(ctx: org.partiql.parser.antlr.PartiQLParser.SchemaFunctionContext?): AstNode { + return super.visitSchemaFunction(ctx) + } + + override fun visitSqlInvokedFunction(ctx: org.partiql.parser.antlr.PartiQLParser.SqlInvokedFunctionContext) = translate(ctx) { + val specification = visitFunctionSpecification(ctx.functionSpecification()) + val body = visitRoutineBody(ctx.routineBody()) + statementDDLCreateFunction(specification, body) + } + + override fun visitFunctionSpecification(ctx: org.partiql.parser.antlr.PartiQLParser.FunctionSpecificationContext) = translate(ctx) { + val root = visitSymbolPrimitive(ctx.name) + val name = identifierQualified(root, emptyList()) + val parameters = ctx.sqlParameterDeclarationList().sqlParameterDeclaration().map { decl -> + visitSqlParameterDeclaration(decl) + } + val returns = visitReturnsClause(ctx.returnsClause()) + val characteristics = ctx.routineCharacteristic().map { characteristic -> + visitRoutineCharacteristic(characteristic) + } + statementDDLCreateFunctionSpecification(name, parameters, returns, characteristics) + } + + override fun visitSqlParameterDeclaration(ctx: org.partiql.parser.antlr.PartiQLParser.SqlParameterDeclarationContext) = translate(ctx) { + val name = ctx.sqlParameterName()?.let { visitSymbolPrimitive(it.symbolPrimitive()) } + val type = visit(ctx.parameterType().type()) as Type + statementDDLCreateFunctionParameterDeclaration(name, type) + } + + override fun visitReturnsClause(ctx: org.partiql.parser.antlr.PartiQLParser.ReturnsClauseContext) = translate(ctx) { + val type = visit(ctx.returnsDataType().type()) as Type + statementDDLCreateFunctionReturns(type) + } + + override fun visitRoutineCharacteristic(ctx: org.partiql.parser.antlr.PartiQLParser.RoutineCharacteristicContext) = translate(ctx) { + val name = visitSymbolPrimitive(ctx.specificName().name) + val specificName = identifierQualified(name, emptyList()) + statementRoutineCharacteristicSpecific(specificName) + } + + override fun visitReturnStatement(ctx: org.partiql.parser.antlr.PartiQLParser.ReturnStatementContext) = translate(ctx) { + val expr = visitExpr(ctx.expr()) + statementReturn(expr) + } + + override fun visitSqlProcedureStatement(ctx: org.partiql.parser.antlr.PartiQLParser.SqlProcedureStatementContext?): AstNode { + return super.visitSqlProcedureStatement(ctx) + } + + override fun visitSqlExecutableStatement(ctx: org.partiql.parser.antlr.PartiQLParser.SqlExecutableStatementContext?): AstNode { + return super.visitSqlExecutableStatement(ctx) + } + + override fun visitRoutineBody(ctx: org.partiql.parser.antlr.PartiQLParser.RoutineBodyContext) = translate(ctx) { + visitSqlRoutineBody(ctx.sqlRoutineBody()) + } + + override fun visitSqlRoutineBody(ctx: org.partiql.parser.antlr.PartiQLParser.SqlRoutineBodyContext) = translate(ctx) { + val stmt = visitSqlProcedureStatement(ctx.sqlProcedureStatement()) as Statement + statementRoutineBodyInternal(stmt) + } + + override fun visitSqlControlStatement(ctx: org.partiql.parser.antlr.PartiQLParser.SqlControlStatementContext?): AstNode { + return super.visitSqlControlStatement(ctx) + } + /** * * DATA MANIPULATION LANGUAGE (DML) @@ -1835,6 +1911,7 @@ internal class PartiQLParserDefault : PartiQLParser { val n = ctx.arg0?.text?.toInt() when (ctx.datatype.type) { GeneratedParser.FLOAT -> when (n) { + null -> typeFloat64() 32 -> typeFloat32() 64 -> typeFloat64() else -> throw error(ctx.datatype, "Invalid FLOAT precision. Expected 32 or 64") diff --git a/partiql-parser/src/main/resources/built-in-functions/README.md b/partiql-parser/src/main/resources/built-in-functions/README.md new file mode 100644 index 0000000000..587eae643f --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/README.md @@ -0,0 +1,157 @@ +# SQL:1999 + +- CML is the implementation-defined maximum length for +- BML is the implementation-defined maximum length for bit string length +- MP is the implementation-defined maximum precision for +- P1 is the implementation-defined precision for the value of a +- P2 is the implementation-defined precision for the value of a +- MBP is the implementation-defined maximum binary precision for +- MILFP is the implementation-defined maximum value for +- MIFSP is the implementation-defined maximum value for . +- Let P assume all character string values that are the minimal literal for an exact numeric value of scale 0 (zero) between 1 (one) and MP +- let S assume all character string values that are the minimal literal for an exact numeric value of scale 0 (zero) between 1 (one) and P +- let BP assume all character string values that are the minimal literal for an exact numeric value of scale 0 (zero) between 1 (one) and MBP +- let IP assume all character string values that are the minimal literal for an exact numeric value of scale 0 (zero) between 1 (one) and MILFP +- let IS assume all character string values that are the minimal literal for an exact numeric value of scale 0 (zero) between 0 (zero) and MIFSP. + +## Remaining Grants + +```sql + +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.POSITION1 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.POSITION2 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.POSITION3 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.POSITION4 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.CHAR_LENGTH1 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.CHAR_LENGTH2 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.CHAR_LENGTH3 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.CHAR_LENGTH4 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.CHARACTER_LENGTH1 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.CHARACTER_LENGTH2 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.CHARACTER_LENGTH3 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.CHARACTER_LENGTH4 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.OCTET_LENGTH1 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.OCTET_LENGTH2 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.OCTET_LENGTH3 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.OCTET_LENGTH4 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.BIT_LENGTH1 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.BIT_LENGTH2 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.BIT_LENGTH3 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.BIT_LENGTH4 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.ABSNUMERICP_S + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.ABSDECIMALP_S + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.ABSINTEGER + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.ABSSMALLINT + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.ABSFLOATBP + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.ABSREAL + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.ABSDOUBLEPRECISION + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.MODNUMERICMP_NUMERICP + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.MODNUMERICMP_DECIMALP + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.MODNUMERICMP_INTEGER + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.MODNUMERICMP_SMALLINT + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.MODDECIMALMP_NUMERICP + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.MODDECIMALMP_DECIMALP + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.MODDECIMALMP_INTEGER + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.MODDECIMALMP_SMALLINT + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.MODINTEGER_NUMERICP + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.MODINTEGER_DECIMALP + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.MODINTEGER_INTEGER + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.MODINTEGER_SMALLINT + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.MODSMALLINT_NUMERICP + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.MODSMALLINT_DECIMALP + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.MODSMALLINT_INTEGER + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.MODSMALLINT_SMALLINT + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.ABSINTERVALYEARIP + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.ABSINTERVALYEARIP_MONTH + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.ABSINTERVALMONTHIP + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.ABSINTERVALDAYIP + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.ABSINTERVALDAYIP_HOUR + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.ABSINTERVALDAYIP_MINUTE + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.ABSINTERVALDAYIP_SECONDIS + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.ABSINTERVALHOURIP + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.ABSINTERVALHOURIP_MINUTE + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.ABSINTERVALHOURIP_SECONDIS + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.ABSINTERVALMINUTEIP + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.ABSINTERVALMINUTEIP_SECONDIS + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.ABSINTERVALSECONDIP_IS + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.SUBSTRING1 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.SUBSTRING2 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.SUBSTRING3 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.SUBSTRING4 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.SUBSTRING5 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.SUBSTRING6 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.SUBSTRING7 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.SUBSTRING8 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.UPPER1 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.UPPER2 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.LOWER1 + TO PUBLIC; +GRANT EXECUTE ON SPECIFIC FUNCTION INFORMATION_SCHEMA.LOWER2 + TO PUBLIC; +``` \ No newline at end of file diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSDECIMALP_S.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSDECIMALP_S.sql new file mode 100644 index 0000000000..36b27deb24 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSDECIMALP_S.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "ABS"( + N DECIMAL ) + RETURNS DECIMAL + SPECIFIC ABSDECIMALP_S + RETURN ABS ( N ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSDOUBLEPRECISION.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSDOUBLEPRECISION.sql new file mode 100644 index 0000000000..89954214ab --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSDOUBLEPRECISION.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "ABS"( + N DOUBLE PRECISION) + RETURNS DOUBLE PRECISION + SPECIFIC ABSDOUBLEPRECISION + RETURN ABS(N) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSFLOATBP.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSFLOATBP.sql new file mode 100644 index 0000000000..2b7267434b --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSFLOATBP.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "ABS"( + N FLOAT ) + RETURNS FLOAT + SPECIFIC ABSFLOATBP + RETURN ABS ( N ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSINTEGER.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSINTEGER.sql new file mode 100644 index 0000000000..a808e0e6c5 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSINTEGER.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "ABS"( + N INTEGER) + RETURNS INTEGER + SPECIFIC ABSINTEGER + RETURN ABS(N) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSNUMERICP_S.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSNUMERICP_S.sql new file mode 100644 index 0000000000..c36beb3a43 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSNUMERICP_S.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "ABS"( + N NUMERIC ) +RETURNS NUMERIC +SPECIFIC ABSNUMERICP_S +RETURN ABS ( N ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSREAL.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSREAL.sql new file mode 100644 index 0000000000..0032d05576 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSREAL.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "ABS"( + N REAL) + RETURNS REAL + SPECIFIC ABSREAL + RETURN ABS(N) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSSMALLINT.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSSMALLINT.sql new file mode 100644 index 0000000000..b4c48f64de --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/ABSSMALLINT.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "ABS"( + N SMALLINT) + RETURNS SMALLINT + SPECIFIC ABSSMALLINT + RETURN ABS(N) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/BIT_LENGTH1.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/BIT_LENGTH1.sql new file mode 100644 index 0000000000..8ea5ce7c4e --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/BIT_LENGTH1.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "BIT_LENGTH"( + S1 CHARACTER ) +RETURNS NUMERIC +SPECIFIC BIT_LENGTH1 +RETURN BIT_LENGTH ( S1 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/BIT_LENGTH2.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/BIT_LENGTH2.sql new file mode 100644 index 0000000000..42fb947200 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/BIT_LENGTH2.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "BIT_LENGTH"( + S1 CHARACTER VARYING) +RETURNS NUMERIC +SPECIFIC BIT_LENGTH2 +RETURN BIT_LENGTH ( S1 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/CHARACTER_LENGTH1.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/CHARACTER_LENGTH1.sql new file mode 100644 index 0000000000..c54f19a2a8 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/CHARACTER_LENGTH1.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "CHARACTER_LENGTH"( + S1 CHARACTER ) +RETURNS NUMERIC +SPECIFIC CHARACTER_LENGTH1 +RETURN CHARACTER_LENGTH ( S1 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/CHARACTER_LENGTH2.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/CHARACTER_LENGTH2.sql new file mode 100644 index 0000000000..b11141c7be --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/CHARACTER_LENGTH2.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "CHARACTER_LENGTH"( + S1 CHARACTER VARYING ) +RETURNS NUMERIC +SPECIFIC CHARACTER_LENGTH2 +RETURN CHARACTER_LENGTH ( S1 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/CHAR_LENGTH1.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/CHAR_LENGTH1.sql new file mode 100644 index 0000000000..c4743b24a9 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/CHAR_LENGTH1.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "CHAR_LENGTH"( + S1 CHARACTER ) +RETURNS NUMERIC +SPECIFIC CHAR_LENGTH1 +RETURN CHAR_LENGTH ( S1 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/CHAR_LENGTH2.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/CHAR_LENGTH2.sql new file mode 100644 index 0000000000..28319ddb5a --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/CHAR_LENGTH2.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "CHAR_LENGTH"( + S1 CHARACTER VARYING ) +RETURNS NUMERIC +SPECIFIC CHAR_LENGTH2 +RETURN CHAR_LENGTH ( S1 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/LOWER1.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/LOWER1.sql new file mode 100644 index 0000000000..c4fe33b944 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/LOWER1.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "LOWER"( + S CHARACTER ) +RETURNS CHARACTER +SPECIFIC LOWER1 +RETURN LOWER ( S ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/LOWER2.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/LOWER2.sql new file mode 100644 index 0000000000..fa12e8770d --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/LOWER2.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "LOWER"( + S CHARACTER VARYING) +RETURNS CHARACTER VARYING +SPECIFIC LOWER2 +RETURN LOWER ( S ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODDECIMALMP_DECIMALP.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODDECIMALMP_DECIMALP.sql new file mode 100644 index 0000000000..3b348c73b1 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODDECIMALMP_DECIMALP.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 DECIMAL, +N2 DECIMAL) +RETURNS DECIMAL +SPECIFIC MODDECIMALMP_DECIMALP +RETURN MOD ( N1, N2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODDECIMALMP_INTEGER.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODDECIMALMP_INTEGER.sql new file mode 100644 index 0000000000..6249098267 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODDECIMALMP_INTEGER.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 DECIMAL, +N2 INTEGER ) +RETURNS INTEGER +SPECIFIC MODDECIMALMP_INTEGER +RETURN MOD ( N1, N2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODDECIMALMP_NUMERICP.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODDECIMALMP_NUMERICP.sql new file mode 100644 index 0000000000..a581ae1fa5 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODDECIMALMP_NUMERICP.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 DECIMAL, +N2 NUMERIC ) +RETURNS NUMERIC +SPECIFIC MODDECIMALMP_NUMERICP +RETURN MOD ( N1, N2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODDECIMALMP_SMALLINT.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODDECIMALMP_SMALLINT.sql new file mode 100644 index 0000000000..acb22fdc2c --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODDECIMALMP_SMALLINT.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 DECIMAL, +N2 SMALLINT ) +RETURNS SMALLINT +SPECIFIC MODDECIMALMP_SMALLINT +RETURN MOD ( N1, N2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODINTEGER_DECIMALP.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODINTEGER_DECIMALP.sql new file mode 100644 index 0000000000..9090888287 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODINTEGER_DECIMALP.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 INTEGER, + N2 DECIMAL) +RETURNS DECIMAL +SPECIFIC MODINTEGER_DECIMALP +RETURN MOD ( N1, N2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODINTEGER_INTEGER.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODINTEGER_INTEGER.sql new file mode 100644 index 0000000000..37f9d32959 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODINTEGER_INTEGER.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 INTEGER, + N2 INTEGER) + RETURNS INTEGER + SPECIFIC MODINTEGER_INTEGER + RETURN MOD(N1, N2) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODINTEGER_NUMERICP.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODINTEGER_NUMERICP.sql new file mode 100644 index 0000000000..c9f5e42293 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODINTEGER_NUMERICP.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 INTEGER, + N2 NUMERIC ) +RETURNS NUMERIC +SPECIFIC MODINTEGER_NUMERICP +RETURN MOD ( N1, N2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODINTEGER_SMALLINT.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODINTEGER_SMALLINT.sql new file mode 100644 index 0000000000..6e12d3f59e --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODINTEGER_SMALLINT.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 INTEGER, + N2 SMALLINT) + RETURNS SMALLINT + SPECIFIC MODINTEGER_SMALLINT + RETURN MOD(N1, N2) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODNUMERICMP_DECIMALP.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODNUMERICMP_DECIMALP.sql new file mode 100644 index 0000000000..80c55eefdd --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODNUMERICMP_DECIMALP.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 NUMERIC, +N2 DECIMAL ) +RETURNS DECIMAL +SPECIFIC MODNUMERICMP_DECIMALP +RETURN MOD ( N1, N2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODNUMERICMP_INTEGER.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODNUMERICMP_INTEGER.sql new file mode 100644 index 0000000000..55cc2762a0 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODNUMERICMP_INTEGER.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 NUMERIC, +N2 INTEGER ) +RETURNS INTEGER +SPECIFIC MODNUMERICMP_INTEGER +RETURN MOD ( N1, N2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODNUMERICMP_NUMERICP.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODNUMERICMP_NUMERICP.sql new file mode 100644 index 0000000000..c2bb72099c --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODNUMERICMP_NUMERICP.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 NUMERIC, +N2 NUMERIC) +RETURNS NUMERIC +SPECIFIC MODNUMERICMP_NUMERICP +RETURN MOD ( N1, N2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODNUMERICMP_SMALLINT.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODNUMERICMP_SMALLINT.sql new file mode 100644 index 0000000000..f4390f8026 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODNUMERICMP_SMALLINT.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 NUMERIC, +N2 SMALLINT ) +RETURNS SMALLINT +SPECIFIC MODNUMERICMP_SMALLINT +RETURN MOD ( N1, N2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODSMALLINT_DECIMALP.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODSMALLINT_DECIMALP.sql new file mode 100644 index 0000000000..d284f3273e --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODSMALLINT_DECIMALP.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 SMALLINT, + N2 DECIMAL) +RETURNS DECIMAL +SPECIFIC MODSMALLINT_DECIMALP +RETURN MOD ( N1, N2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODSMALLINT_INTEGER.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODSMALLINT_INTEGER.sql new file mode 100644 index 0000000000..05a93a46ac --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODSMALLINT_INTEGER.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 SMALLINT, + N2 INTEGER) + RETURNS INTEGER + SPECIFIC MODSMALLINT_INTEGER + RETURN MOD(N1, N2) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODSMALLINT_NUMERICP.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODSMALLINT_NUMERICP.sql new file mode 100644 index 0000000000..53707170f0 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODSMALLINT_NUMERICP.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 SMALLINT, + N2 NUMERIC ) +RETURNS NUMERIC +SPECIFIC MODSMALLINT_NUMERICP +RETURN MOD ( N1, N2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODSMALLINT_SMALLINT.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODSMALLINT_SMALLINT.sql new file mode 100644 index 0000000000..f7b2e036dc --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/MODSMALLINT_SMALLINT.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 SMALLINT, + N2 SMALLINT) + RETURNS SMALLINT + SPECIFIC MODSMALLINT_SMALLINT + RETURN MOD(N1, N2) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/OCTET_LENGTH1.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/OCTET_LENGTH1.sql new file mode 100644 index 0000000000..e53cf8970a --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/OCTET_LENGTH1.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "OCTET_LENGTH"( + S1 CHARACTER) +RETURNS NUMERIC +SPECIFIC OCTET_LENGTH1 +RETURN OCTET_LENGTH ( S1 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/OCTET_LENGTH2.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/OCTET_LENGTH2.sql new file mode 100644 index 0000000000..0033d637a5 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/OCTET_LENGTH2.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "OCTET_LENGTH"( + S1 CHARACTER VARYING) +RETURNS NUMERIC +SPECIFIC OCTET_LENGTH2 +RETURN OCTET_LENGTH ( S1 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/POSITION1.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/POSITION1.sql new file mode 100644 index 0000000000..87982642e7 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/POSITION1.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "POSITION" ( + S1 CHARACTER, + S2 CHARACTER ) + RETURNS NUMERIC + SPECIFIC POSITION1 + RETURN POSITION ( S1 IN S2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/POSITION2.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/POSITION2.sql new file mode 100644 index 0000000000..9adab3d7bd --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/POSITION2.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "POSITION" ( + S1 CHARACTER VARYING, + S2 CHARACTER ) + RETURNS NUMERIC + SPECIFIC POSITION2 + RETURN POSITION ( S1 IN S2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/POSITION3.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/POSITION3.sql new file mode 100644 index 0000000000..feb16f6fdf --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/POSITION3.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "POSITION"( + S1 CHARACTER, + S2 CHARACTER VARYING ) + RETURNS NUMERIC + SPECIFIC POSITION3 + RETURN POSITION ( S1 IN S2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/POSITION4.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/POSITION4.sql new file mode 100644 index 0000000000..106759e3b8 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/POSITION4.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "POSITION"( + S1 CHARACTER VARYING, + S2 CHARACTER VARYING) + RETURNS NUMERIC + SPECIFIC POSITION4 + RETURN POSITION ( S1 IN S2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/SUBSTRING1.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/SUBSTRING1.sql new file mode 100644 index 0000000000..7a120d7214 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/SUBSTRING1.sql @@ -0,0 +1,7 @@ +CREATE FUNCTION "SUBSTRING"( + S CHARACTER, +START NUMERIC, +LENGTH NUMERIC ) +RETURNS CHARACTER VARYING +SPECIFIC SUBSTRING1 +RETURN SUBSTRING ( S FROM START FOR LENGTH ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/SUBSTRING2.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/SUBSTRING2.sql new file mode 100644 index 0000000000..83848301ac --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/SUBSTRING2.sql @@ -0,0 +1,7 @@ +CREATE FUNCTION "SUBSTRING"( + S CHARACTER VARYING, +START NUMERIC, +LENGTH NUMERIC ) +RETURNS CHARACTER VARYING +SPECIFIC SUBSTRING2 +RETURN SUBSTRING ( S FROM START FOR LENGTH ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/SUBSTRING3.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/SUBSTRING3.sql new file mode 100644 index 0000000000..1af98c555f --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/SUBSTRING3.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "SUBSTRING"( + S CHARACTER, +START NUMERIC ) +RETURNS CHARACTER VARYING +SPECIFIC SUBSTRING3 +RETURN SUBSTRING ( S FROM START ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/SUBSTRING4.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/SUBSTRING4.sql new file mode 100644 index 0000000000..5cf5a406d4 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/SUBSTRING4.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "SUBSTRING"( + S CHARACTER VARYING, +START NUMERIC ) +RETURNS CHARACTER VARYING +SPECIFIC SUBSTRING4 +RETURN SUBSTRING ( S FROM START ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/UPPER1.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/UPPER1.sql new file mode 100644 index 0000000000..3f040a430c --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/UPPER1.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "UPPER"( + S CHARACTER ) +RETURNS CHARACTER +SPECIFIC UPPER1 +RETURN UPPER ( S ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/partiql-converted/UPPER2.sql b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/UPPER2.sql new file mode 100644 index 0000000000..9d3e03d03d --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/partiql-converted/UPPER2.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "UPPER"( + S CHARACTER VARYING ) +RETURNS CHARACTER VARYING +SPECIFIC UPPER2 +RETURN UPPER ( S ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/ABSDECIMALP_S.sql b/partiql-parser/src/main/resources/built-in-functions/sql/ABSDECIMALP_S.sql new file mode 100644 index 0000000000..6af12e88b5 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/ABSDECIMALP_S.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "ABS"( + N DECIMAL ( P, S ) ) + RETURNS DECIMAL ( P, S ) + SPECIFIC ABSDECIMALP_S + RETURN ABS ( N ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/ABSDOUBLEPRECISION.sql b/partiql-parser/src/main/resources/built-in-functions/sql/ABSDOUBLEPRECISION.sql new file mode 100644 index 0000000000..89954214ab --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/ABSDOUBLEPRECISION.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "ABS"( + N DOUBLE PRECISION) + RETURNS DOUBLE PRECISION + SPECIFIC ABSDOUBLEPRECISION + RETURN ABS(N) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/ABSFLOATBP.sql b/partiql-parser/src/main/resources/built-in-functions/sql/ABSFLOATBP.sql new file mode 100644 index 0000000000..2b7267434b --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/ABSFLOATBP.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "ABS"( + N FLOAT ) + RETURNS FLOAT + SPECIFIC ABSFLOATBP + RETURN ABS ( N ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/ABSINTEGER.sql b/partiql-parser/src/main/resources/built-in-functions/sql/ABSINTEGER.sql new file mode 100644 index 0000000000..a808e0e6c5 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/ABSINTEGER.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "ABS"( + N INTEGER) + RETURNS INTEGER + SPECIFIC ABSINTEGER + RETURN ABS(N) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/ABSNUMERICP_S.sql b/partiql-parser/src/main/resources/built-in-functions/sql/ABSNUMERICP_S.sql new file mode 100644 index 0000000000..0a494e56f0 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/ABSNUMERICP_S.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "ABS"( + N NUMERIC ( P, S ) ) +RETURNS NUMERIC ( P, S ) +SPECIFIC ABSNUMERICP_S +RETURN ABS ( N ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/ABSREAL.sql b/partiql-parser/src/main/resources/built-in-functions/sql/ABSREAL.sql new file mode 100644 index 0000000000..0032d05576 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/ABSREAL.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "ABS"( + N REAL) + RETURNS REAL + SPECIFIC ABSREAL + RETURN ABS(N) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/ABSSMALLINT.sql b/partiql-parser/src/main/resources/built-in-functions/sql/ABSSMALLINT.sql new file mode 100644 index 0000000000..b4c48f64de --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/ABSSMALLINT.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "ABS"( + N SMALLINT) + RETURNS SMALLINT + SPECIFIC ABSSMALLINT + RETURN ABS(N) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/BIT_LENGTH1.sql b/partiql-parser/src/main/resources/built-in-functions/sql/BIT_LENGTH1.sql new file mode 100644 index 0000000000..0e918587ff --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/BIT_LENGTH1.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "BIT_LENGTH"( + S1 CHARACTER ( CML ) ) +RETURNS NUMERIC ( P2, 0 ) +SPECIFIC BIT_LENGTH1 +RETURN BIT_LENGTH ( S1 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/BIT_LENGTH2.sql b/partiql-parser/src/main/resources/built-in-functions/sql/BIT_LENGTH2.sql new file mode 100644 index 0000000000..9d79b74beb --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/BIT_LENGTH2.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "BIT_LENGTH"( + S1 CHARACTER VARYING ( CML ) ) +RETURNS NUMERIC ( P2, 0 ) +SPECIFIC BIT_LENGTH2 +RETURN BIT_LENGTH ( S1 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/CHARACTER_LENGTH1.sql b/partiql-parser/src/main/resources/built-in-functions/sql/CHARACTER_LENGTH1.sql new file mode 100644 index 0000000000..cc6c4a218d --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/CHARACTER_LENGTH1.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "CHARACTER_LENGTH"( + S1 CHARACTER ( CML ) ) +RETURNS NUMERIC ( P2, 0 ) +SPECIFIC CHARACTER_LENGTH1 +RETURN CHARACTER_LENGTH ( S1 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/CHARACTER_LENGTH2.sql b/partiql-parser/src/main/resources/built-in-functions/sql/CHARACTER_LENGTH2.sql new file mode 100644 index 0000000000..bce69b0ba2 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/CHARACTER_LENGTH2.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "CHARACTER_LENGTH"( + S1 CHARACTER VARYING ( CML ) ) +RETURNS NUMERIC ( P2, 0 ) +SPECIFIC CHARACTER_LENGTH2 +RETURN CHARACTER_LENGTH ( S1 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/CHAR_LENGTH1.sql b/partiql-parser/src/main/resources/built-in-functions/sql/CHAR_LENGTH1.sql new file mode 100644 index 0000000000..011f9f1f73 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/CHAR_LENGTH1.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "CHAR_LENGTH"( + S1 CHARACTER ( CML ) ) +RETURNS NUMERIC ( P2, 0 ) +SPECIFIC CHAR_LENGTH1 +RETURN CHAR_LENGTH ( S1 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/CHAR_LENGTH2.sql b/partiql-parser/src/main/resources/built-in-functions/sql/CHAR_LENGTH2.sql new file mode 100644 index 0000000000..12d67bd67c --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/CHAR_LENGTH2.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "CHAR_LENGTH"( + S1 CHARACTER VARYING ( CML ) ) +RETURNS NUMERIC ( P2, 0 ) +SPECIFIC CHAR_LENGTH2 +RETURN CHAR_LENGTH ( S1 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/LOWER1.sql b/partiql-parser/src/main/resources/built-in-functions/sql/LOWER1.sql new file mode 100644 index 0000000000..fbe4f22729 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/LOWER1.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "LOWER"( + S CHARACTER ( CML ) ) +RETURNS CHARACTER ( CML ) +SPECIFIC LOWER1 +RETURN LOWER ( S ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/LOWER2.sql b/partiql-parser/src/main/resources/built-in-functions/sql/LOWER2.sql new file mode 100644 index 0000000000..855fd2e7a9 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/LOWER2.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "LOWER"( + S CHARACTER VARYING ( CML ) ) +RETURNS CHARACTER VARYING ( CML ) +SPECIFIC LOWER2 +RETURN LOWER ( S ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/MODDECIMALMP_DECIMALP.sql b/partiql-parser/src/main/resources/built-in-functions/sql/MODDECIMALMP_DECIMALP.sql new file mode 100644 index 0000000000..ffcdc150e2 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/MODDECIMALMP_DECIMALP.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 DECIMAL ( MP, 0 ), +N2 DECIMAL ( P, 0 ) ) +RETURNS DECIMAL ( P, 0 ) +SPECIFIC MODDECIMALMP_DECIMALP +RETURN MOD ( N1, N2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/MODDECIMALMP_INTEGER.sql b/partiql-parser/src/main/resources/built-in-functions/sql/MODDECIMALMP_INTEGER.sql new file mode 100644 index 0000000000..9aece334d3 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/MODDECIMALMP_INTEGER.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 DECIMAL ( MP, 0 ), +N2 INTEGER ) +RETURNS INTEGER +SPECIFIC MODDECIMALMP_INTEGER +RETURN MOD ( N1, N2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/MODDECIMALMP_NUMERICP.sql b/partiql-parser/src/main/resources/built-in-functions/sql/MODDECIMALMP_NUMERICP.sql new file mode 100644 index 0000000000..944b6e3572 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/MODDECIMALMP_NUMERICP.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 DECIMAL ( MP, 0 ), +N2 NUMERIC ( P, 0 ) ) +RETURNS NUMERIC ( P, 0 ) +SPECIFIC MODDECIMALMP_NUMERICP +RETURN MOD ( N1, N2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/MODDECIMALMP_SMALLINT.sql b/partiql-parser/src/main/resources/built-in-functions/sql/MODDECIMALMP_SMALLINT.sql new file mode 100644 index 0000000000..bf3891371f --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/MODDECIMALMP_SMALLINT.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 DECIMAL ( MP, 0 ), +N2 SMALLINT ) +RETURNS SMALLINT +SPECIFIC MODDECIMALMP_SMALLINT +RETURN MOD ( N1, N2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/MODINTEGER_DECIMALP.sql b/partiql-parser/src/main/resources/built-in-functions/sql/MODINTEGER_DECIMALP.sql new file mode 100644 index 0000000000..5b45fb1ba3 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/MODINTEGER_DECIMALP.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 INTEGER, + N2 DECIMAL ( P, 0 ) ) +RETURNS DECIMAL ( P, 0 ) +SPECIFIC MODINTEGER_DECIMALP +RETURN MOD ( N1, N2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/MODINTEGER_INTEGER.sql b/partiql-parser/src/main/resources/built-in-functions/sql/MODINTEGER_INTEGER.sql new file mode 100644 index 0000000000..37f9d32959 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/MODINTEGER_INTEGER.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 INTEGER, + N2 INTEGER) + RETURNS INTEGER + SPECIFIC MODINTEGER_INTEGER + RETURN MOD(N1, N2) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/MODINTEGER_NUMERICP.sql b/partiql-parser/src/main/resources/built-in-functions/sql/MODINTEGER_NUMERICP.sql new file mode 100644 index 0000000000..2396f41bfe --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/MODINTEGER_NUMERICP.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 INTEGER, + N2 NUMERIC ( P, 0 ) ) +RETURNS NUMERIC ( P, 0 ) +SPECIFIC MODINTEGER_NUMERICP +RETURN MOD ( N1, N2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/MODINTEGER_SMALLINT.sql b/partiql-parser/src/main/resources/built-in-functions/sql/MODINTEGER_SMALLINT.sql new file mode 100644 index 0000000000..6e12d3f59e --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/MODINTEGER_SMALLINT.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 INTEGER, + N2 SMALLINT) + RETURNS SMALLINT + SPECIFIC MODINTEGER_SMALLINT + RETURN MOD(N1, N2) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/MODNUMERICMP_DECIMALP.sql b/partiql-parser/src/main/resources/built-in-functions/sql/MODNUMERICMP_DECIMALP.sql new file mode 100644 index 0000000000..50d9f60c13 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/MODNUMERICMP_DECIMALP.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 NUMERIC ( MP, 0 ), +N2 DECIMAL ( P, 0 ) ) +RETURNS DECIMAL ( P, 0 ) +SPECIFIC MODNUMERICMP_DECIMALP +RETURN MOD ( N1, N2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/MODNUMERICMP_INTEGER.sql b/partiql-parser/src/main/resources/built-in-functions/sql/MODNUMERICMP_INTEGER.sql new file mode 100644 index 0000000000..e1b9329f1e --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/MODNUMERICMP_INTEGER.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 NUMERIC ( MP, 0 ), +N2 INTEGER ) +RETURNS INTEGER +SPECIFIC MODNUMERICMP_INTEGER +RETURN MOD ( N1, N2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/MODNUMERICMP_NUMERICP.sql b/partiql-parser/src/main/resources/built-in-functions/sql/MODNUMERICMP_NUMERICP.sql new file mode 100644 index 0000000000..de4769f00b --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/MODNUMERICMP_NUMERICP.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 NUMERIC ( MP, 0 ), +N2 NUMERIC ( P, 0 ) ) +RETURNS NUMERIC ( P, 0 ) +SPECIFIC MODNUMERICMP_NUMERICP +RETURN MOD ( N1, N2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/MODNUMERICMP_SMALLINT.sql b/partiql-parser/src/main/resources/built-in-functions/sql/MODNUMERICMP_SMALLINT.sql new file mode 100644 index 0000000000..c0070f9391 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/MODNUMERICMP_SMALLINT.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 NUMERIC ( MP, 0 ), +N2 SMALLINT ) +RETURNS SMALLINT +SPECIFIC MODNUMERICMP_SMALLINT +RETURN MOD ( N1, N2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/MODSMALLINT_DECIMALP.sql b/partiql-parser/src/main/resources/built-in-functions/sql/MODSMALLINT_DECIMALP.sql new file mode 100644 index 0000000000..dec3a51216 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/MODSMALLINT_DECIMALP.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 SMALLINT, + N2 DECIMAL ( P, 0 ) ) +RETURNS DECIMAL ( P, 0 ) +SPECIFIC MODSMALLINT_DECIMALP +RETURN MOD ( N1, N2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/MODSMALLINT_INTEGER.sql b/partiql-parser/src/main/resources/built-in-functions/sql/MODSMALLINT_INTEGER.sql new file mode 100644 index 0000000000..05a93a46ac --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/MODSMALLINT_INTEGER.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 SMALLINT, + N2 INTEGER) + RETURNS INTEGER + SPECIFIC MODSMALLINT_INTEGER + RETURN MOD(N1, N2) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/MODSMALLINT_NUMERICP.sql b/partiql-parser/src/main/resources/built-in-functions/sql/MODSMALLINT_NUMERICP.sql new file mode 100644 index 0000000000..2c765596a0 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/MODSMALLINT_NUMERICP.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 SMALLINT, + N2 NUMERIC ( P, 0 ) ) +RETURNS NUMERIC ( P, 0 ) +SPECIFIC MODSMALLINT_NUMERICP +RETURN MOD ( N1, N2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/MODSMALLINT_SMALLINT.sql b/partiql-parser/src/main/resources/built-in-functions/sql/MODSMALLINT_SMALLINT.sql new file mode 100644 index 0000000000..f7b2e036dc --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/MODSMALLINT_SMALLINT.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "MOD"( + N1 SMALLINT, + N2 SMALLINT) + RETURNS SMALLINT + SPECIFIC MODSMALLINT_SMALLINT + RETURN MOD(N1, N2) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/OCTET_LENGTH1.sql b/partiql-parser/src/main/resources/built-in-functions/sql/OCTET_LENGTH1.sql new file mode 100644 index 0000000000..22e215cde5 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/OCTET_LENGTH1.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "OCTET_LENGTH"( + S1 CHARACTER ( CML ) ) +RETURNS NUMERIC ( P2, 0 ) +SPECIFIC OCTET_LENGTH1 +RETURN OCTET_LENGTH ( S1 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/OCTET_LENGTH2.sql b/partiql-parser/src/main/resources/built-in-functions/sql/OCTET_LENGTH2.sql new file mode 100644 index 0000000000..dfb29335ef --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/OCTET_LENGTH2.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "OCTET_LENGTH"( + S1 CHARACTER VARYING ( CML ) ) +RETURNS NUMERIC ( P2, 0 ) +SPECIFIC OCTET_LENGTH2 +RETURN OCTET_LENGTH ( S1 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/POSITION1.sql b/partiql-parser/src/main/resources/built-in-functions/sql/POSITION1.sql new file mode 100644 index 0000000000..735739c7d8 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/POSITION1.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "POSITION" ( + S1 CHARACTER ( CML ), + S2 CHARACTER ( CML ) ) + RETURNS NUMERIC ( P1, 0 ) + SPECIFIC POSITION1 + RETURN POSITION ( S1 IN S2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/POSITION2.sql b/partiql-parser/src/main/resources/built-in-functions/sql/POSITION2.sql new file mode 100644 index 0000000000..9af6cbbea9 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/POSITION2.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "POSITION" ( + S1 CHARACTER VARYING ( CML ), + S2 CHARACTER ( CML ) ) + RETURNS NUMERIC ( P1, 0 ) + SPECIFIC POSITION2 + RETURN POSITION ( S1 IN S2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/POSITION3.sql b/partiql-parser/src/main/resources/built-in-functions/sql/POSITION3.sql new file mode 100644 index 0000000000..8398e6d1c9 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/POSITION3.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "POSITION"( + S1 CHARACTER ( CML ), + S2 CHARACTER VARYING ( CML ) ) + RETURNS NUMERIC ( P1, 0 ) + SPECIFIC POSITION3 + RETURN POSITION ( S1 IN S2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/POSITION4.sql b/partiql-parser/src/main/resources/built-in-functions/sql/POSITION4.sql new file mode 100644 index 0000000000..38443093e8 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/POSITION4.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "POSITION"( + S1 CHARACTER VARYING ( CML ), + S2 CHARACTER VARYING ( CML ) ) + RETURNS NUMERIC ( P1, 0 ) + SPECIFIC POSITION4 + RETURN POSITION ( S1 IN S2 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/SUBSTRING1.sql b/partiql-parser/src/main/resources/built-in-functions/sql/SUBSTRING1.sql new file mode 100644 index 0000000000..02c276c115 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/SUBSTRING1.sql @@ -0,0 +1,7 @@ +CREATE FUNCTION "SUBSTRING"( + S CHARACTER ( CML ), +START NUMERIC ( MP, 0 ), +LENGTH NUMERIC ( MP, 0 ) ) +RETURNS CHARACTER VARYING ( CML ) +SPECIFIC SUBSTRING1 +RETURN SUBSTRING ( S FROM START FOR LENGTH ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/SUBSTRING2.sql b/partiql-parser/src/main/resources/built-in-functions/sql/SUBSTRING2.sql new file mode 100644 index 0000000000..48b8b14640 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/SUBSTRING2.sql @@ -0,0 +1,7 @@ +CREATE FUNCTION "SUBSTRING"( + S CHARACTER VARYING ( CML ), +START NUMERIC ( MP, 0 ), +LENGTH NUMERIC ( MP, 0 ) ) +RETURNS CHARACTER VARYING ( CML ) +SPECIFIC SUBSTRING2 +RETURN SUBSTRING ( S FROM START FOR LENGTH ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/SUBSTRING3.sql b/partiql-parser/src/main/resources/built-in-functions/sql/SUBSTRING3.sql new file mode 100644 index 0000000000..f420996c3c --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/SUBSTRING3.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "SUBSTRING"( + S CHARACTER ( CML ), +START NUMERIC ( MP, 0 ) ) +RETURNS CHARACTER VARYING ( CML ) +SPECIFIC SUBSTRING3 +RETURN SUBSTRING ( S FROM START ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/SUBSTRING4.sql b/partiql-parser/src/main/resources/built-in-functions/sql/SUBSTRING4.sql new file mode 100644 index 0000000000..c473d528d5 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/SUBSTRING4.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "SUBSTRING"( + S CHARACTER VARYING ( CML ), +START NUMERIC ( MP, 0 ) ) +RETURNS CHARACTER VARYING ( CML ) +SPECIFIC SUBSTRING4 +RETURN SUBSTRING ( S FROM START ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/UPPER1.sql b/partiql-parser/src/main/resources/built-in-functions/sql/UPPER1.sql new file mode 100644 index 0000000000..a52744d405 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/UPPER1.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "UPPER"( + S CHARACTER ( CML ) ) +RETURNS CHARACTER ( CML ) +SPECIFIC UPPER1 +RETURN UPPER ( S ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/UPPER2.sql b/partiql-parser/src/main/resources/built-in-functions/sql/UPPER2.sql new file mode 100644 index 0000000000..650ab45afe --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/UPPER2.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "UPPER"( + S CHARACTER VARYING ( CML ) ) +RETURNS CHARACTER VARYING ( CML ) +SPECIFIC UPPER2 +RETURN UPPER ( S ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALDAYIP.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALDAYIP.sql new file mode 100644 index 0000000000..a59a543de5 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALDAYIP.sql @@ -0,0 +1,7 @@ +CREATE FUNCTION "ABS"( + N INTERVAL ( DAY ( IP ))) + RETURNS INTERVAL + (DAY ( IP)) + SPECIFIC ABSINTERVALDAYIP + RETURN ABS ( N ) ; + diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALDAYIP_HOUR.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALDAYIP_HOUR.sql new file mode 100644 index 0000000000..2a19b2456a --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALDAYIP_HOUR.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "ABS"( + N INTERVAL ( DAY ( IP ) TO HOUR)) + RETURNS INTERVAL + (DAY ( IP) TO HOUR) + SPECIFIC ABSINTERVALDAYIP_HOUR + RETURN ABS ( N ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALDAYIP_MINUTE.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALDAYIP_MINUTE.sql new file mode 100644 index 0000000000..3afc3d84fd --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALDAYIP_MINUTE.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "ABS"( + N INTERVAL ( DAY ( IP ) TO MINUTE)) + RETURNS INTERVAL + (DAY ( IP) TO MINUTE) + SPECIFIC ABSINTERVALDAYIP_MINUTE + RETURN ABS ( N ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALDAYIP_SECONDIS.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALDAYIP_SECONDIS.sql new file mode 100644 index 0000000000..3ab96359a7 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALDAYIP_SECONDIS.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "ABS"( + N INTERVAL ( DAY ( IP ) TO SECOND ( IS ))) + RETURNS INTERVAL + (DAY ( IP) TO SECOND (IS)) + SPECIFIC ABSINTERVALDAYIP_SECONDIS + RETURN ABS ( N ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALHOURIP.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALHOURIP.sql new file mode 100644 index 0000000000..9d6417173f --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALHOURIP.sql @@ -0,0 +1,7 @@ +CREATE FUNCTION "ABS"( + N INTERVAL ( HOUR ( IP ))) + RETURNS INTERVAL + (HOUR ( IP)) + SPECIFIC ABSINTERVALHOURIP + RETURN ABS ( N ) ; + diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALHOURIP_MINUTE.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALHOURIP_MINUTE.sql new file mode 100644 index 0000000000..8f83daaea8 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALHOURIP_MINUTE.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "ABS"( + N INTERVAL ( HOUR ( IP ) TO MINUTE)) + RETURNS INTERVAL + (HOUR ( IP) TO MINUTE) + SPECIFIC ABSINTERVALHOURIP_MINUTE + RETURN ABS ( N ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALHOURIP_SECONDIS.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALHOURIP_SECONDIS.sql new file mode 100644 index 0000000000..90a9521242 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALHOURIP_SECONDIS.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "ABS"( + N INTERVAL ( HOUR ( IP ) TO SECOND ( IS ))) + RETURNS INTERVAL + (HOUR ( IP) TO SECOND (IS)) + SPECIFIC ABSINTERVALHOURIP_SECONDIS + RETURN ABS ( N ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALMINUTEIP.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALMINUTEIP.sql new file mode 100644 index 0000000000..a5fa613406 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALMINUTEIP.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "ABS"( + N INTERVAL ( MINUTE ( IP ))) + RETURNS INTERVAL + (MINUTE ( IP)) + SPECIFIC ABSINTERVALMINUTEIP + RETURN ABS ( N ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALMINUTEIP_SECONDIS.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALMINUTEIP_SECONDIS.sql new file mode 100644 index 0000000000..28fcf7a443 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALMINUTEIP_SECONDIS.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "ABS"( + N INTERVAL ( MINUTE ( IP ) TO SECOND ( IS ))) + RETURNS INTERVAL + (MINUTE ( IP) TO SECOND (IS)) + SPECIFIC ABSINTERVALMINUTEIP_SECONDIS + RETURN ABS ( N ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALMONTHIP.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALMONTHIP.sql new file mode 100644 index 0000000000..6be8135de1 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALMONTHIP.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "ABS"( + N INTERVAL ( MONTH ( IP ))) + RETURNS INTERVAL + (MONTH ( IP)) + SPECIFIC ABSINTERVALMONTHIP + RETURN ABS ( N ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALSECONDIP_IS.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALSECONDIP_IS.sql new file mode 100644 index 0000000000..6d76f549f1 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALSECONDIP_IS.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "ABS"( + N INTERVAL ( SECOND ( IP , IS ))) + RETURNS INTERVAL + (SECOND ( IP , IS)) + SPECIFIC ABSINTERVALSECONDIP_IS + RETURN ABS ( N ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALYEARIP.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALYEARIP.sql new file mode 100644 index 0000000000..e57c08652e --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALYEARIP.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "ABS"( + N INTERVAL ( YEAR ( IP ))) + RETURNS INTERVAL + (YEAR ( IP)) + SPECIFIC ABSINTERVALYEARIP + RETURN ABS ( N ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALYEARIP_MONTH.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALYEARIP_MONTH.sql new file mode 100644 index 0000000000..ff57b8b7ff --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/ABSINTERVALYEARIP_MONTH.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "ABS"( + N INTERVAL ( YEAR ( IP ) TO MONTH)) + RETURNS INTERVAL + (YEAR ( IP) TO MONTH) + SPECIFIC ABSINTERVALYEARIP_MONTH + RETURN ABS ( N ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/BIT_LENGTH3.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/BIT_LENGTH3.sql new file mode 100644 index 0000000000..afe359d7ed --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/BIT_LENGTH3.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "BIT_LENGTH"( + S1 BIT ( BML ) ) +RETURNS NUMERIC ( P2, 0 ) +SPECIFIC BIT_LENGTH3 +RETURN BIT_LENGTH ( S1 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/BIT_LENGTH4.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/BIT_LENGTH4.sql new file mode 100644 index 0000000000..de94d136ab --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/BIT_LENGTH4.sql @@ -0,0 +1,6 @@ + +CREATE FUNCTION "BIT_LENGTH"( + S1 BIT VARYING ( BML ) ) +RETURNS NUMERIC ( P2, 0 ) +SPECIFIC BIT_LENGTH4 +RETURN BIT_LENGTH ( S1 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/CHARACTER_LENGTH3.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/CHARACTER_LENGTH3.sql new file mode 100644 index 0000000000..a922f766af --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/CHARACTER_LENGTH3.sql @@ -0,0 +1,6 @@ + +CREATE FUNCTION "CHARACTER_LENGTH"( + S1 BIT ( BML ) ) +RETURNS NUMERIC ( P2, 0 ) +SPECIFIC CHARACTER_LENGTH3 +RETURN CHARACTER_LENGTH ( S1 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/CHARACTER_LENGTH4.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/CHARACTER_LENGTH4.sql new file mode 100644 index 0000000000..06ba26ab0b --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/CHARACTER_LENGTH4.sql @@ -0,0 +1,6 @@ + +CREATE FUNCTION "CHARACTER_LENGTH"( + S1 BIT VARYING ( BML ) ) +RETURNS NUMERIC ( P2, 0 ) +SPECIFIC CHARACTER_LENGTH4 +RETURN CHARACTER_LENGTH ( S1 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/CHAR_LENGTH3.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/CHAR_LENGTH3.sql new file mode 100644 index 0000000000..2b64ffe13e --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/CHAR_LENGTH3.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "CHAR_LENGTH"( + S1 BIT ( BML ) ) +RETURNS NUMERIC ( P2, 0 ) +SPECIFIC CHAR_LENGTH3 +RETURN CHAR_LENGTH ( S1 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/CHAR_LENGTH4.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/CHAR_LENGTH4.sql new file mode 100644 index 0000000000..0557bfa83a --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/CHAR_LENGTH4.sql @@ -0,0 +1,6 @@ + +CREATE FUNCTION "CHAR_LENGTH"( + S1 BIT VARYING ( BML ) ) +RETURNS NUMERIC ( P2, 0 ) +SPECIFIC CHAR_LENGTH4 +RETURN CHAR_LENGTH ( S1 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/OCTET_LENGTH3.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/OCTET_LENGTH3.sql new file mode 100644 index 0000000000..9722e872fe --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/OCTET_LENGTH3.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "OCTET_LENGTH"( + S1 BIT ( BML ) ) +RETURNS NUMERIC ( P2, 0 ) +SPECIFIC OCTET_LENGTH3 +RETURN OCTET_LENGTH ( S1 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/OCTET_LENGTH4.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/OCTET_LENGTH4.sql new file mode 100644 index 0000000000..f6bf7e38b4 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/OCTET_LENGTH4.sql @@ -0,0 +1,5 @@ +CREATE FUNCTION "OCTET_LENGTH"( + S1 BIT VARYING ( BML ) ) +RETURNS NUMERIC ( P2, 0 ) +SPECIFIC OCTET_LENGTH4 +RETURN OCTET_LENGTH ( S1 ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/SUBSTRING5.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/SUBSTRING5.sql new file mode 100644 index 0000000000..c8d2f00cdd --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/SUBSTRING5.sql @@ -0,0 +1,7 @@ +CREATE FUNCTION "SUBSTRING"( + S BIT ( BML ), +START NUMERIC ( MP, 0 ), +LENGTH NUMERIC ( MP, 0 ) ) +RETURNS BIT VARYING ( BML ) +SPECIFIC SUBSTRING5 +RETURN SUBSTRING ( S FROM START FOR LENGTH ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/SUBSTRING6.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/SUBSTRING6.sql new file mode 100644 index 0000000000..e07f127660 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/SUBSTRING6.sql @@ -0,0 +1,7 @@ +CREATE FUNCTION "SUBSTRING"( + S BIT VARYING ( BML ), +START NUMERIC ( MP, 0 ), +LENGTH NUMERIC ( MP, 0 ) ) +RETURNS BIT VARYING ( BML ) +SPECIFIC SUBSTRING6 +RETURN SUBSTRING ( S FROM START FOR LENGTH ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/SUBSTRING7.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/SUBSTRING7.sql new file mode 100644 index 0000000000..82b2407663 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/SUBSTRING7.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "SUBSTRING"( + S BIT ( BML ), +START NUMERIC ( MP, 0 ) ) +RETURNS BIT VARYING ( BML ) +SPECIFIC SUBSTRING7 +RETURN SUBSTRING ( S FROM START ) ; diff --git a/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/SUBSTRING8.sql b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/SUBSTRING8.sql new file mode 100644 index 0000000000..210b1417e4 --- /dev/null +++ b/partiql-parser/src/main/resources/built-in-functions/sql/parse-failures/SUBSTRING8.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION "SUBSTRING"( + S BIT VARYING ( BML ), +START NUMERIC ( MP, 0 ) ) +RETURNS BIT VARYING ( BML ) +SPECIFIC SUBSTRING8 +RETURN SUBSTRING ( S FROM START ) ; diff --git a/partiql-parser/src/test/kotlin/org/partiql/parser/impl/PartiQLParserDefaultTests.kt b/partiql-parser/src/test/kotlin/org/partiql/parser/impl/PartiQLParserDefaultTests.kt new file mode 100644 index 0000000000..8f167ddb09 --- /dev/null +++ b/partiql-parser/src/test/kotlin/org/partiql/parser/impl/PartiQLParserDefaultTests.kt @@ -0,0 +1,237 @@ +package org.partiql.parser.impl + +import org.junit.jupiter.api.assertDoesNotThrow +import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.api.extension.ExtensionContext +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.Arguments +import org.junit.jupiter.params.provider.ArgumentsProvider +import org.junit.jupiter.params.provider.ArgumentsSource +import org.partiql.ast.Ast +import org.partiql.ast.AstNode +import org.partiql.ast.Identifier +import org.partiql.parser.PartiQLParserException +import org.partiql.value.PartiQLValueExperimental +import org.partiql.value.decimalValue +import java.io.File +import java.util.stream.Stream + +class PartiQLParserDefaultTests { + + private val parser = PartiQLParserDefault() + + data class ParserTestCase( + val input: String, + val expected: AstNode + ) + + // TODO: Add expected exception information + data class ParserFailingTestCase( + val input: String, + ) + + @ParameterizedTest + @ArgumentsSource(HandwrittenFunctionTestCases::class) + fun test(tc: ParserTestCase) { + val result = assertDoesNotThrow { parser.parse(tc.input) } + // TODO: Once we can assert equality: + // assertEquals(tc.expected, result.root) + } + + @ParameterizedTest + @ArgumentsSource(CreateBuiltInFunctionTestCases::class) + fun testPartiQLBuiltIns(tc: ParserTestCase) { + val result = assertDoesNotThrow { parser.parse(tc.input) } + // TODO: Once we can assert equality: + // assertEquals(tc.expected, result.root) + } + + @ParameterizedTest + @ArgumentsSource(FailingTestCases::class) + fun testMalformedQueries(tc: ParserFailingTestCase) { + val exception = assertThrows { parser.parse(tc.input) } + // TODO: Assert some locations? + } + + class HandwrittenFunctionTestCases : ArgumentsProviderBase() { + @OptIn(PartiQLValueExperimental::class) + override fun getParameters(): List = listOf( + ParserTestCase( + input = """ + CREATE FUNCTION PI () RETURNS DECIMAL RETURN 3.14; + """.trimIndent(), + expected = Ast.statementDDLCreateFunction( + specification = Ast.statementDDLCreateFunctionSpecification( + name = Ast.identifierQualified( + root = Ast.identifierSymbol("PI", caseSensitivity = Identifier.CaseSensitivity.INSENSITIVE), + steps = emptyList() + ), + parameters = emptyList(), + returns = Ast.statementDDLCreateFunctionReturns( + type = Ast.typeDecimal(null, null) + ), + characteristics = emptyList() + ), + body = Ast.statementRoutineBodyInternal( + procedureStatement = Ast.statementReturn( + value = Ast.exprLit(decimalValue(3.14.toBigDecimal())) + ) + ) + ) + ), + ParserTestCase( + input = """ + CREATE FUNCTION "MOD" ( + N1 DECIMAL ( 10, 0 ), + N2 DECIMAL ( 10, 0 ) ) + RETURNS DECIMAL ( 10, 0 ) + SPECIFIC MODDECIMALMP_DECIMALP + RETURN MOD ( N1, N2 ) ; + """.trimIndent(), + expected = Ast.typeNullType() // TODO + ), + ParserTestCase( + input = """ + CREATE FUNCTION "MOD" ( + N2 DECIMAL ( 10, 0 ) ) + RETURNS DECIMAL ( 10, 0 ) + SPECIFIC MODDECIMALMP_DECIMALP + RETURN MOD ( N1, N2 ) ; + """.trimIndent(), + expected = Ast.typeNullType() // TODO + ), + ParserTestCase( + input = """ + CREATE FUNCTION "BIT_LENGTH"( + S1 CHARACTER VARYING) + RETURNS NUMERIC + SPECIFIC BIT_LENGTH2 + RETURN BIT_LENGTH ( S1 ) ; + """.trimIndent(), + expected = Ast.typeNullType() // TODO + ), + // Without parameter name + ParserTestCase( + input = """ + CREATE FUNCTION "BIT_LENGTH"( + CHARACTER VARYING) + RETURNS NUMERIC + SPECIFIC BIT_LENGTH2 + RETURN BIT_LENGTH ( S1 ) ; + """.trimIndent(), + expected = Ast.typeNullType() // TODO + ), + // Custom type + ParserTestCase( + input = """ + CREATE FUNCTION HelloWorld (a custom_type) RETURNS INT RETURN 1; + """.trimIndent(), + expected = Ast.typeNullType() // TODO + ), + // Custom type without param name + ParserTestCase( + input = """ + CREATE FUNCTION HelloWorld (custom_type) RETURNS INT RETURN 1; + """.trimIndent(), + expected = Ast.typeNullType() // TODO + ), + // Pre-defined type without param name + ParserTestCase( + input = """ + CREATE FUNCTION HelloWorld (INT) RETURNS INT RETURN 1; + """.trimIndent(), + expected = Ast.typeNullType() // TODO + ), + ) + } + + class CreateBuiltInFunctionTestCases : ArgumentsProviderBase() { + private val loader: ClassLoader = PartiQLParserDefault::class.java.classLoader + private val resource = loader.getResource("built-in-functions/partiql-converted")!! + private val file = File(resource.toURI()) + override fun getParameters() = file.listFiles()!!.map { statementFile -> + val statement = statementFile.readText() + ParserTestCase(input = statement, expected = Ast.typeNullType()) + } + } + + class FailingTestCases : ArgumentsProviderBase() { + override fun getParameters() = listOf( + // Missing FUNCTION + ParserFailingTestCase( + input = """ + CREATE FUNC HelloWorld () RETURNS INT RETURN 1; + """.trimIndent() + ), + // No PARENS + ParserFailingTestCase( + input = """ + CREATE FUNCTION HelloWorld RETURNS INT RETURN 1; + """.trimIndent() + ), + // RETURN before RETURNS + ParserFailingTestCase( + input = """ + CREATE FUNCTION HelloWorld () RETURN 1 RETURNS INT; + """.trimIndent() + ), + // COMMA in arguments + ParserFailingTestCase( + input = """ + CREATE FUNCTION HelloWorld (,) RETURNS INT RETURN 1; + """.trimIndent() + ), + // SPECIFIC before RETURNS + ParserFailingTestCase( + input = """ + CREATE FUNCTION HelloWorld () SPECIFIC HelloWorld1 RETURNS INT RETURN 1; + """.trimIndent() + ), + // Missing return + ParserFailingTestCase( + input = """ + CREATE FUNCTION HelloWorld () RETURNS INT; + """.trimIndent() + ), + // TODO: This should eventually pass + ParserFailingTestCase( + input = """ + CREATE FUNCTION SomeCatalog.HelloWorld () RETURNS INT RETURN 1; + """.trimIndent() + ), + // Trailing COMMA + ParserFailingTestCase( + input = """ + CREATE FUNCTION HelloWorld (a INT,) RETURNS INT RETURN 1; + """.trimIndent() + ), + // Expression instead of RETURN + ParserFailingTestCase( + input = """ + CREATE FUNCTION HelloWorld (a INT) RETURNS INT 1; + """.trimIndent() + ), + // Expression instead of RETURN + ParserFailingTestCase( + input = """ + CREATE FUNCTION HelloWorld (a INT) RETURNS INT SELECT 1 FROM <<>>; + """.trimIndent() + ), + // SPECIFIC not name + ParserFailingTestCase( + input = """ + CREATE FUNCTION HelloWorld (a INT) RETURNS INT SPECIFIC 1 RETURN 1; + """.trimIndent() + ), + ) + } + + abstract class ArgumentsProviderBase : ArgumentsProvider { + abstract fun getParameters(): List + + @Throws(Exception::class) + override fun provideArguments(extensionContext: ExtensionContext): Stream? { + return getParameters().map { Arguments.of(it) }.stream() + } + } +}