Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add-call-with to sdk #2337

Merged
merged 5 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
227 changes: 221 additions & 6 deletions pkg/sdk/procedures_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ var (
procedurePackage = g.NewQueryStruct("ProcedurePackage").Text("Package", g.KeywordOptions().SingleQuotes().Required())
)

// https://docs.snowflake.com/en/sql-reference/constructs/with and https://docs.snowflake.com/en/user-guide/queries-cte
var procedureWithClause = g.NewQueryStruct("ProcedureWithClause").
Identifier("CteName", g.KindOfT[AccountObjectIdentifier](), g.IdentifierOptions().Required()).
PredefinedQueryStructField("CteColumns", "[]string", g.KeywordOptions().Parentheses()).
PredefinedQueryStructField("Statement", "string", g.ParameterOptions().NoEquals().NoQuotes().SQL("AS").Required())

var ProceduresDef = g.NewInterface(
"Procedures",
"Procedure",
Expand Down Expand Up @@ -102,8 +108,8 @@ var ProceduresDef = g.NewInterface(
PredefinedQueryStructField("ExecuteAs", "*ExecuteAs", g.KeywordOptions()).
PredefinedQueryStructField("ProcedureDefinition", "*string", g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS")).
WithValidation(g.ValidateValueSet, "RuntimeVersion").
WithValidation(g.ValidateValueSet, "Handler").
WithValidation(g.ValidateValueSet, "Packages").
WithValidation(g.ValidateValueSet, "Handler").
WithValidation(g.ValidIdentifier, "name"),
).CustomOperation(
"CreateForJavaScript",
Expand Down Expand Up @@ -169,8 +175,8 @@ var ProceduresDef = g.NewInterface(
PredefinedQueryStructField("ExecuteAs", "*ExecuteAs", g.KeywordOptions()).
PredefinedQueryStructField("ProcedureDefinition", "*string", g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS")).
WithValidation(g.ValidateValueSet, "RuntimeVersion").
WithValidation(g.ValidateValueSet, "Handler").
WithValidation(g.ValidateValueSet, "Packages").
WithValidation(g.ValidateValueSet, "Handler").
WithValidation(g.ValidIdentifier, "name"),
).CustomOperation(
"CreateForScala",
Expand Down Expand Up @@ -211,8 +217,8 @@ var ProceduresDef = g.NewInterface(
PredefinedQueryStructField("ExecuteAs", "*ExecuteAs", g.KeywordOptions()).
PredefinedQueryStructField("ProcedureDefinition", "*string", g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS")).
WithValidation(g.ValidateValueSet, "RuntimeVersion").
WithValidation(g.ValidateValueSet, "Handler").
WithValidation(g.ValidateValueSet, "Packages").
WithValidation(g.ValidateValueSet, "Handler").
WithValidation(g.ValidIdentifier, "name"),
).CustomOperation(
"CreateForSQL",
Expand Down Expand Up @@ -248,7 +254,7 @@ var ProceduresDef = g.NewInterface(
SQL("PROCEDURE").
IfExists().
Name().
PredefinedQueryStructField("ArgumentDataTypes", "[]DataType", g.KeywordOptions().Parentheses().Required()).
PredefinedQueryStructField("ArgumentDataTypes", "[]DataType", g.KeywordOptions().MustParentheses().Required()).
OptionalIdentifier("RenameTo", g.KindOfT[SchemaObjectIdentifier](), g.IdentifierOptions().SQL("RENAME TO")).
OptionalTextAssignment("SET COMMENT", g.ParameterOptions().SingleQuotes()).
OptionalTextAssignment("SET LOG_LEVEL", g.ParameterOptions().SingleQuotes()).
Expand All @@ -267,7 +273,7 @@ var ProceduresDef = g.NewInterface(
SQL("PROCEDURE").
IfExists().
Name().
PredefinedQueryStructField("ArgumentDataTypes", "[]DataType", g.KeywordOptions().Parentheses().Required()).
PredefinedQueryStructField("ArgumentDataTypes", "[]DataType", g.KeywordOptions().MustParentheses().Required()).
WithValidation(g.ValidIdentifier, "name"),
).ShowOperation(
"https://docs.snowflake.com/en/sql-reference/sql/show-procedures",
Expand Down Expand Up @@ -319,6 +325,215 @@ var ProceduresDef = g.NewInterface(
Describe().
SQL("PROCEDURE").
Name().
PredefinedQueryStructField("ArgumentDataTypes", "[]DataType", g.KeywordOptions().Parentheses().Required()).
PredefinedQueryStructField("ArgumentDataTypes", "[]DataType", g.KeywordOptions().MustParentheses().Required()).
WithValidation(g.ValidIdentifier, "name"),
).CustomOperation(
"Call",
"https://docs.snowflake.com/en/sql-reference/sql/call",
g.NewQueryStruct("Call").
SQL("CALL").
Name().
PredefinedQueryStructField("CallArguments", "[]string", g.KeywordOptions().MustParentheses()).
PredefinedQueryStructField("ScriptingVariable", "*string", g.ParameterOptions().NoEquals().NoQuotes().SQL("INTO")).
WithValidation(g.ValidIdentifier, "name"),
).CustomOperation(
"CreateAndCallForJava",
"https://docs.snowflake.com/en/sql-reference/sql/call-with#java-and-scala",
g.NewQueryStruct("CreateAndCallForJava").
SQL("WITH").
Identifier("Name", g.KindOfT[AccountObjectIdentifier](), g.IdentifierOptions().Required()).
SQL("AS PROCEDURE").
ListQueryStructField(
"Arguments",
procedureArgument,
g.ListOptions().MustParentheses(),
).
QueryStructField(
"Returns",
procedureReturns,
g.KeywordOptions().SQL("RETURNS").Required(),
).
SQL("LANGUAGE JAVA").
TextAssignment("RUNTIME_VERSION", g.ParameterOptions().SingleQuotes().Required()).
ListQueryStructField(
"Packages",
procedurePackage,
g.ParameterOptions().Parentheses().SQL("PACKAGES").Required(),
).
ListQueryStructField(
"Imports",
procedureImport,
g.ParameterOptions().Parentheses().SQL("IMPORTS"),
).
TextAssignment("HANDLER", g.ParameterOptions().SingleQuotes().Required()).
PredefinedQueryStructField("NullInputBehavior", "*NullInputBehavior", g.KeywordOptions()).
PredefinedQueryStructField("ProcedureDefinition", "*string", g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS")).
OptionalQueryStructField(
"WithClause",
procedureWithClause,
g.KeywordOptions(),
).
SQL("CALL").
Identifier("ProcedureName", g.KindOfT[AccountObjectIdentifier](), g.IdentifierOptions().Required()).
PredefinedQueryStructField("CallArguments", "[]string", g.KeywordOptions().MustParentheses()).
PredefinedQueryStructField("ScriptingVariable", "*string", g.ParameterOptions().NoEquals().NoQuotes().SQL("INTO")).
WithValidation(g.ValidateValueSet, "RuntimeVersion").
WithValidation(g.ValidateValueSet, "Packages").
WithValidation(g.ValidateValueSet, "Handler").
WithValidation(g.ValidIdentifier, "ProcedureName").
WithValidation(g.ValidIdentifier, "Name"),
).CustomOperation(
"CreateAndCallForScala",
"https://docs.snowflake.com/en/sql-reference/sql/call-with#java-and-scala",
g.NewQueryStruct("CreateAndCallForScala").
SQL("WITH").
Identifier("Name", g.KindOfT[AccountObjectIdentifier](), g.IdentifierOptions().Required()).
SQL("AS PROCEDURE").
ListQueryStructField(
"Arguments",
procedureArgument,
g.ListOptions().MustParentheses(),
).
QueryStructField(
"Returns",
procedureReturns,
g.KeywordOptions().SQL("RETURNS").Required(),
).
SQL("LANGUAGE SCALA").
TextAssignment("RUNTIME_VERSION", g.ParameterOptions().SingleQuotes().Required()).
ListQueryStructField(
"Packages",
procedurePackage,
g.ParameterOptions().Parentheses().SQL("PACKAGES").Required(),
).
ListQueryStructField(
"Imports",
procedureImport,
g.ParameterOptions().Parentheses().SQL("IMPORTS"),
).
TextAssignment("HANDLER", g.ParameterOptions().SingleQuotes().Required()).
PredefinedQueryStructField("NullInputBehavior", "*NullInputBehavior", g.KeywordOptions()).
PredefinedQueryStructField("ProcedureDefinition", "*string", g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS")).
ListQueryStructField(
"WithClauses",
procedureWithClause,
g.KeywordOptions(),
).
SQL("CALL").
Identifier("ProcedureName", g.KindOfT[AccountObjectIdentifier](), g.IdentifierOptions().Required()).
PredefinedQueryStructField("CallArguments", "[]string", g.KeywordOptions().MustParentheses()).
PredefinedQueryStructField("ScriptingVariable", "*string", g.ParameterOptions().NoEquals().NoQuotes().SQL("INTO")).
WithValidation(g.ValidateValueSet, "RuntimeVersion").
WithValidation(g.ValidateValueSet, "Packages").
WithValidation(g.ValidateValueSet, "Handler").
WithValidation(g.ValidIdentifier, "ProcedureName").
WithValidation(g.ValidIdentifier, "Name"),
).CustomOperation(
"CreateAndCallForJavaScript",
"https://docs.snowflake.com/en/sql-reference/sql/call-with#javascript",
g.NewQueryStruct("CreateAndCallForJavaScript").
SQL("WITH").
Identifier("Name", g.KindOfT[AccountObjectIdentifier](), g.IdentifierOptions().Required()).
SQL("AS PROCEDURE").
ListQueryStructField(
"Arguments",
procedureArgument,
g.ListOptions().MustParentheses(),
).
PredefinedQueryStructField("ResultDataType", "DataType", g.ParameterOptions().NoEquals().SQL("RETURNS").Required()).
OptionalSQL("NOT NULL").
SQL("LANGUAGE JAVASCRIPT").
PredefinedQueryStructField("NullInputBehavior", "*NullInputBehavior", g.KeywordOptions()).
PredefinedQueryStructField("ProcedureDefinition", "string", g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS").Required()).
ListQueryStructField(
"WithClauses",
procedureWithClause,
g.KeywordOptions(),
).
SQL("CALL").
Identifier("ProcedureName", g.KindOfT[AccountObjectIdentifier](), g.IdentifierOptions().Required()).
PredefinedQueryStructField("CallArguments", "[]string", g.KeywordOptions().MustParentheses()).
PredefinedQueryStructField("ScriptingVariable", "*string", g.ParameterOptions().NoEquals().NoQuotes().SQL("INTO")).
WithValidation(g.ValidateValueSet, "ProcedureDefinition").
WithValidation(g.ValidateValueSet, "ResultDataType").
WithValidation(g.ValidIdentifier, "ProcedureName").
WithValidation(g.ValidIdentifier, "Name"),
).CustomOperation(
"CreateAndCallForPython",
"https://docs.snowflake.com/en/sql-reference/sql/call-with#python",
g.NewQueryStruct("CreateAndCallForPython").
SQL("WITH").
Identifier("Name", g.KindOfT[AccountObjectIdentifier](), g.IdentifierOptions().Required()).
SQL("AS PROCEDURE").
ListQueryStructField(
"Arguments",
procedureArgument,
g.ListOptions().MustParentheses(),
).
QueryStructField(
"Returns",
procedureReturns,
g.KeywordOptions().SQL("RETURNS").Required(),
).
SQL("LANGUAGE PYTHON").
TextAssignment("RUNTIME_VERSION", g.ParameterOptions().SingleQuotes().Required()).
ListQueryStructField(
"Packages",
procedurePackage,
g.ParameterOptions().Parentheses().SQL("PACKAGES").Required(),
).
ListQueryStructField(
"Imports",
procedureImport,
g.ParameterOptions().Parentheses().SQL("IMPORTS"),
).
TextAssignment("HANDLER", g.ParameterOptions().SingleQuotes().Required()).
PredefinedQueryStructField("NullInputBehavior", "*NullInputBehavior", g.KeywordOptions()).
PredefinedQueryStructField("ProcedureDefinition", "*string", g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS")).
ListQueryStructField(
"WithClauses",
procedureWithClause,
g.KeywordOptions(),
).
SQL("CALL").
Identifier("ProcedureName", g.KindOfT[AccountObjectIdentifier](), g.IdentifierOptions().Required()).
PredefinedQueryStructField("CallArguments", "[]string", g.KeywordOptions().MustParentheses()).
PredefinedQueryStructField("ScriptingVariable", "*string", g.ParameterOptions().NoEquals().NoQuotes().SQL("INTO")).
WithValidation(g.ValidateValueSet, "RuntimeVersion").
WithValidation(g.ValidateValueSet, "Packages").
WithValidation(g.ValidateValueSet, "Handler").
WithValidation(g.ValidIdentifier, "ProcedureName").
WithValidation(g.ValidIdentifier, "Name"),
).CustomOperation(
"CreateAndCallForSQL",
"https://docs.snowflake.com/en/sql-reference/sql/call-with#snowflake-scripting",
g.NewQueryStruct("CreateAndCallForSQL").
SQL("WITH").
Identifier("Name", g.KindOfT[AccountObjectIdentifier](), g.IdentifierOptions().Required()).
SQL("AS PROCEDURE").
ListQueryStructField(
"Arguments",
procedureArgument,
g.ListOptions().MustParentheses(),
).
QueryStructField(
"Returns",
procedureReturns,
g.KeywordOptions().SQL("RETURNS").Required(),
).
SQL("LANGUAGE SQL").
PredefinedQueryStructField("NullInputBehavior", "*NullInputBehavior", g.KeywordOptions()).
PredefinedQueryStructField("ProcedureDefinition", "string", g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS").Required()).
ListQueryStructField(
"WithClauses",
procedureWithClause,
g.KeywordOptions(),
).
SQL("CALL").
Identifier("ProcedureName", g.KindOfT[AccountObjectIdentifier](), g.IdentifierOptions().Required()).
PredefinedQueryStructField("CallArguments", "[]string", g.KeywordOptions().MustParentheses()).
PredefinedQueryStructField("ScriptingVariable", "*string", g.ParameterOptions().NoEquals().NoQuotes().SQL("INTO")).
WithValidation(g.ValidateValueSet, "ProcedureDefinition").
WithValidation(g.ValidIdentifier, "ProcedureName").
WithValidation(g.ValidIdentifier, "Name"),
)
Loading
Loading