diff --git a/internal/codegen/golang/query.go b/internal/codegen/golang/query.go index 7cda1b7c2b..52be2ecceb 100644 --- a/internal/codegen/golang/query.go +++ b/internal/codegen/golang/query.go @@ -297,7 +297,9 @@ func (v QueryValue) YDBParamMapEntries() string { // ydbBuilderMethodForColumnType maps a YDB column data type to a ParamsBuilder method name. func ydbBuilderMethodForColumnType(dbType string) string { - switch strings.ToLower(dbType) { + baseType := extractBaseType(strings.ToLower(dbType)) + + switch baseType { case "bool": return "Bool" case "uint64": diff --git a/internal/codegen/golang/ydb_type.go b/internal/codegen/golang/ydb_type.go index 0ef665aee1..0a4db80a3b 100644 --- a/internal/codegen/golang/ydb_type.go +++ b/internal/codegen/golang/ydb_type.go @@ -12,9 +12,11 @@ import ( func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Column) string { columnType := strings.ToLower(sdk.DataType(col.Type)) - notNull := col.NotNull || col.IsArray + notNull := (col.NotNull || col.IsArray) && !isNullableType(columnType) emitPointersForNull := options.EmitPointersForNullTypes + columnType = extractBaseType(columnType) + // https://ydb.tech/docs/ru/yql/reference/types/ // ydb-go-sdk doesn't support sql.Null* yet switch columnType { @@ -49,7 +51,7 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col } // return "sql.NullInt16" return "*int16" - case "int", "int32": //ydb doesn't have int type, but we need it to support untyped constants + case "int", "int32": //ydb doesn't have int type, but we need it to support untyped constants if notNull { return "int32" } @@ -159,7 +161,7 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col return "*string" } return "*string" - + case "date", "date32", "datetime", "timestamp", "tzdate", "tztimestamp", "tzdatetime": if notNull { return "time.Time" @@ -185,3 +187,18 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col } } + +// This function extracts the base type from optional types +func extractBaseType(typeStr string) string { + if strings.HasPrefix(typeStr, "optional<") && strings.HasSuffix(typeStr, ">") { + return strings.TrimSuffix(strings.TrimPrefix(typeStr, "optional<"), ">") + } + if strings.HasSuffix(typeStr, "?") { + return strings.TrimSuffix(typeStr, "?") + } + return typeStr +} + +func isNullableType(typeStr string) bool { + return strings.HasPrefix(typeStr, "optional<") && strings.HasSuffix(typeStr, ">") || strings.HasSuffix(typeStr, "?") +} diff --git a/internal/engine/ydb/convert.go b/internal/engine/ydb/convert.go index 8b67191ce6..0fa339fa56 100755 --- a/internal/engine/ydb/convert.go +++ b/internal/engine/ydb/convert.go @@ -1,6 +1,7 @@ package ydb import ( + "fmt" "log" "strconv" "strings" @@ -1787,7 +1788,15 @@ func (c *cc) VisitType_name_or_bind(n *parser.Type_name_or_bindContext) interfac } return typeName } else if b := n.Bind_parameter(); b != nil { - return &ast.TypeName{Name: "BIND:" + identifier(parseAnIdOrType(b.An_id_or_type()))} + param, ok := b.Accept(c).(ast.Node) + if !ok { + return todo("VisitType_name_or_bind", b) + } + return &ast.TypeName{ + Names: &ast.List{ + Items: []ast.Node{param}, + }, + } } return todo("VisitType_name_or_bind", n) } @@ -1797,6 +1806,8 @@ func (c *cc) VisitType_name(n *parser.Type_nameContext) interface{} { return todo("VisitType_name", n) } + questionCount := len(n.AllQUESTION()) + if composite := n.Type_name_composite(); composite != nil { typeName, ok := composite.Accept(c).(ast.Node) if !ok { @@ -1815,8 +1826,12 @@ func (c *cc) VisitType_name(n *parser.Type_nameContext) interface{} { if !ok { return todo("VisitType_name", decimal.Integer_or_bind(1)) } + name := "decimal" + if questionCount > 0 { + name = name + "?" + } return &ast.TypeName{ - Name: "decimal", + Name: name, TypeOid: 0, Names: &ast.List{ Items: []ast.Node{ @@ -1829,12 +1844,17 @@ func (c *cc) VisitType_name(n *parser.Type_nameContext) interface{} { } if simple := n.Type_name_simple(); simple != nil { + name := simple.GetText() + if questionCount > 0 { + name = name + "?" + } return &ast.TypeName{ - Name: simple.GetText(), + Name: name, TypeOid: 0, } } + // todo: handle multiple ? suffixes return todo("VisitType_name", n) } @@ -1868,19 +1888,7 @@ func (c *cc) VisitType_name_composite(n *parser.Type_name_compositeContext) inte } if opt := n.Type_name_optional(); opt != nil { - if typeName := opt.Type_name_or_bind(); typeName != nil { - tn, ok := typeName.Accept(c).(ast.Node) - if !ok { - return todo("VisitType_name_composite", typeName) - } - return &ast.TypeName{ - Name: "Optional", - TypeOid: 0, - Names: &ast.List{ - Items: []ast.Node{tn}, - }, - } - } + return opt.Accept(c) } if tuple := n.Type_name_tuple(); tuple != nil { @@ -2025,6 +2033,27 @@ func (c *cc) VisitType_name_composite(n *parser.Type_name_compositeContext) inte return todo("VisitType_name_composite", n) } +func (c *cc) VisitType_name_optional(n *parser.Type_name_optionalContext) interface{} { + if n == nil || n.Type_name_or_bind() == nil { + return todo("VisitType_name_optional", n) + } + + tn, ok := n.Type_name_or_bind().Accept(c).(ast.Node) + if !ok { + return todo("VisitType_name_optional", n.Type_name_or_bind()) + } + innerTypeName, ok := tn.(*ast.TypeName) + if !ok { + return todo("VisitType_name_optional", n.Type_name_or_bind()) + } + name := fmt.Sprintf("Optional<%s>", innerTypeName.Name) + return &ast.TypeName{ + Name: name, + TypeOid: 0, + Names: &ast.List{}, + } +} + func (c *cc) VisitSql_stmt_core(n *parser.Sql_stmt_coreContext) interface{} { if n == nil { return todo("VisitSql_stmt_core", n) @@ -2799,13 +2828,28 @@ func (c *cc) handleInvokeSuffix(base ast.Node, invokeCtx *parser.Invoke_exprCont } funcName := strings.Join(nameParts, ".") - if funcName == "coalesce" { + if funcName == "coalesce" || funcName == "nvl" { return &ast.CoalesceExpr{ Args: funcCall.Args, Location: baseNode.Location, } } + if funcName == "greatest" || funcName == "max_of" { + return &ast.MinMaxExpr{ + Op: ast.MinMaxOp(1), + Args: funcCall.Args, + Location: baseNode.Location, + } + } + if funcName == "least" || funcName == "min_of" { + return &ast.MinMaxExpr{ + Op: ast.MinMaxOp(2), + Args: funcCall.Args, + Location: baseNode.Location, + } + } + funcCall.Func = &ast.FuncName{Name: funcName} funcCall.Funcname.Items = append(funcCall.Funcname.Items, &ast.String{Str: funcName}) @@ -2816,15 +2860,12 @@ func (c *cc) handleInvokeSuffix(base ast.Node, invokeCtx *parser.Invoke_exprCont } } - stmt := &ast.RecursiveFuncCall{ - Func: base, - Funcname: funcCall.Funcname, - AggStar: funcCall.AggStar, - Location: funcCall.Location, - Args: funcCall.Args, - AggDistinct: funcCall.AggDistinct, + stmt := &ast.FuncExpr{ + Xpr: base, + Args: funcCall.Args, + Location: funcCall.Location, } - stmt.Funcname.Items = append(stmt.Funcname.Items, base) + return stmt } @@ -2943,16 +2984,42 @@ func (c *cc) VisitId_expr(n *parser.Id_exprContext) interface{} { if n == nil { return todo("VisitId_expr", n) } + + ref := &ast.ColumnRef{ + Fields: &ast.List{}, + Location: c.pos(n.GetStart()), + } + if id := n.Identifier(); id != nil { - return &ast.ColumnRef{ - Fields: &ast.List{ - Items: []ast.Node{ - NewIdentifier(id.GetText()), - }, - }, - Location: c.pos(id.GetStart()), - } + ref.Fields.Items = append(ref.Fields.Items, NewIdentifier(id.GetText())) + return ref + } + + if keyword := n.Keyword_compat(); keyword != nil { + ref.Fields.Items = append(ref.Fields.Items, NewIdentifier(keyword.GetText())) + return ref + } + + if keyword := n.Keyword_alter_uncompat(); keyword != nil { + ref.Fields.Items = append(ref.Fields.Items, NewIdentifier(keyword.GetText())) + return ref + } + + if keyword := n.Keyword_in_uncompat(); keyword != nil { + ref.Fields.Items = append(ref.Fields.Items, NewIdentifier(keyword.GetText())) + return ref + } + + if keyword := n.Keyword_window_uncompat(); keyword != nil { + ref.Fields.Items = append(ref.Fields.Items, NewIdentifier(keyword.GetText())) + return ref + } + + if keyword := n.Keyword_hint_uncompat(); keyword != nil { + ref.Fields.Items = append(ref.Fields.Items, NewIdentifier(keyword.GetText())) + return ref } + return todo("VisitId_expr", n) } @@ -2979,12 +3046,44 @@ func (c *cc) VisitAtom_expr(n *parser.Atom_exprContext) interface{} { return todo("VisitAtom_expr", n.Bind_parameter()) } return expr + case n.Cast_expr() != nil: + expr, ok := n.Cast_expr().Accept(c).(ast.Node) + if !ok { + return todo("VisitAtom_expr", n.Cast_expr()) + } + return expr // TODO: check other cases default: return todo("VisitAtom_expr", n) } } +func (c *cc) VisitCast_expr(n *parser.Cast_exprContext) interface{} { + if n == nil || n.CAST() == nil || n.Expr() == nil || n.AS() == nil || n.Type_name_or_bind() == nil { + return todo("VisitCast_expr", n) + } + + expr, ok := n.Expr().Accept(c).(ast.Node) + if !ok { + return todo("VisitCast_expr", n.Expr()) + } + + temp, ok := n.Type_name_or_bind().Accept(c).(ast.Node) + if !ok { + return todo("VisitCast_expr", n.Type_name_or_bind()) + } + typeName, ok := temp.(*ast.TypeName) + if !ok { + return todo("VisitCast_expr", n.Type_name_or_bind()) + } + + return &ast.TypeCast{ + Arg: expr, + TypeName: typeName, + Location: c.pos(n.GetStart()), + } +} + func (c *cc) VisitLiteral_value(n *parser.Literal_valueContext) interface{} { if n == nil { return todo("VisitLiteral_value", n) diff --git a/internal/engine/ydb/lib/aggregate.go b/internal/engine/ydb/lib/aggregate.go index dfb3924e90..7c5d795eca 100644 --- a/internal/engine/ydb/lib/aggregate.go +++ b/internal/engine/ydb/lib/aggregate.go @@ -8,323 +8,400 @@ import ( func AggregateFunctions() []*catalog.Function { var funcs []*catalog.Function - // COUNT(*) - funcs = append(funcs, &catalog.Function{ - Name: "COUNT", - Args: []*catalog.Argument{}, - ReturnType: &ast.TypeName{Name: "Uint64"}, - }) + funcs = append(funcs, countFuncs()...) + funcs = append(funcs, minMaxFuncs()...) + funcs = append(funcs, sumFuncs()...) + funcs = append(funcs, avgFuncs()...) + funcs = append(funcs, countIfFuncs()...) + funcs = append(funcs, sumIfFuncs()...) + funcs = append(funcs, avgIfFuncs()...) + funcs = append(funcs, someFuncs()...) + funcs = append(funcs, countDistinctEstimateHLLFuncs()...) + funcs = append(funcs, maxByMinByFuncs()...) + funcs = append(funcs, stddevVarianceFuncs()...) + funcs = append(funcs, correlationCovarianceFuncs()...) + funcs = append(funcs, percentileMedianFuncs()...) + funcs = append(funcs, boolAndOrXorFuncs()...) + funcs = append(funcs, bitAndOrXorFuncs()...) - // COUNT(T) и COUNT(T?) - for _, typ := range types { - funcs = append(funcs, &catalog.Function{ - Name: "COUNT", - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - }, - ReturnType: &ast.TypeName{Name: "Uint64"}, - }) - funcs = append(funcs, &catalog.Function{ + // TODO: Aggregate_List, Top, Bottom, Top_By, Bottom_By, TopFreq, Mode, + // Histogram LinearHistogram, LogarithmicHistogram, LogHistogram, CDF, + // SessionStart, AGGREGATE_BY, MULTI_AGGREGATE_BY + + return funcs +} + +func countFuncs() []*catalog.Function { + return []*catalog.Function{ + { Name: "COUNT", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}, Mode: ast.FuncParamVariadic}, + {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Uint64"}, - }) + }, } +} - // MIN и MAX - for _, typ := range types { - funcs = append(funcs, &catalog.Function{ +func minMaxFuncs() []*catalog.Function { + return []*catalog.Function{ + { Name: "MIN", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "any"}}, }, - ReturnType: &ast.TypeName{Name: typ}, - ReturnTypeNullable: true, - }) - funcs = append(funcs, &catalog.Function{ + ReturnType: &ast.TypeName{Name: "any"}, + }, + { Name: "MAX", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "any"}}, }, - ReturnType: &ast.TypeName{Name: typ}, - ReturnTypeNullable: true, - }) + ReturnType: &ast.TypeName{Name: "any"}, + }, } +} - // SUM для unsigned типов - for _, typ := range unsignedTypes { - funcs = append(funcs, &catalog.Function{ +func sumFuncs() []*catalog.Function { + return []*catalog.Function{ + { Name: "SUM", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "any"}}, }, - ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnType: &ast.TypeName{Name: "any"}, ReturnTypeNullable: true, - }) + }, } +} - // SUM для signed типов - for _, typ := range signedTypes { - funcs = append(funcs, &catalog.Function{ - Name: "SUM", +func avgFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "AVG", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "any"}}, }, - ReturnType: &ast.TypeName{Name: "Int64"}, + ReturnType: &ast.TypeName{Name: "any"}, ReturnTypeNullable: true, - }) + }, } +} - // SUM для float/double - for _, typ := range []string{"float", "double"} { - funcs = append(funcs, &catalog.Function{ - Name: "SUM", +func countIfFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "COUNT_IF", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "Bool"}}, }, - ReturnType: &ast.TypeName{Name: typ}, + ReturnType: &ast.TypeName{Name: "Uint64"}, ReturnTypeNullable: true, - }) + }, } +} - // AVG для целочисленных типов - for _, typ := range append(unsignedTypes, signedTypes...) { - funcs = append(funcs, &catalog.Function{ - Name: "AVG", +func sumIfFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "SUM_IF", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Bool"}}, }, - ReturnType: &ast.TypeName{Name: "Double"}, + ReturnType: &ast.TypeName{Name: "any"}, ReturnTypeNullable: true, - }) + }, } +} - // AVG для float/double - for _, typ := range []string{"float", "double"} { - funcs = append(funcs, &catalog.Function{ - Name: "AVG", +func avgIfFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "AVG_IF", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Bool"}}, }, - ReturnType: &ast.TypeName{Name: typ}, + ReturnType: &ast.TypeName{Name: "any"}, ReturnTypeNullable: true, - }) + }, } +} - // COUNT_IF - funcs = append(funcs, &catalog.Function{ - Name: "COUNT_IF", - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: "Bool"}}, - }, - ReturnType: &ast.TypeName{Name: "Uint64"}, - ReturnTypeNullable: true, - }) +func someFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "SOME", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} - // SUM_IF для unsigned - for _, typ := range unsignedTypes { - funcs = append(funcs, &catalog.Function{ - Name: "SUM_IF", +func countDistinctEstimateHLLFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "CountDistinctEstimate", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Uint64"}, ReturnTypeNullable: true, - }) - } - - // SUM_IF для signed - for _, typ := range signedTypes { - funcs = append(funcs, &catalog.Function{ - Name: "SUM_IF", + }, + { + Name: "HyperLogLog", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "any"}}, }, - ReturnType: &ast.TypeName{Name: "Int64"}, + ReturnType: &ast.TypeName{Name: "Uint64"}, ReturnTypeNullable: true, - }) + }, + { + Name: "HLL", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }, } +} - // SUM_IF для float/double - for _, typ := range []string{"float", "double"} { - funcs = append(funcs, &catalog.Function{ - Name: "SUM_IF", +func maxByMinByFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "MAX_BY", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, }, - ReturnType: &ast.TypeName{Name: typ}, + ReturnType: &ast.TypeName{Name: "any"}, ReturnTypeNullable: true, - }) + }, + { + Name: "MIN_BY", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, } + // todo: min/max_by with third argument returning list +} - // AVG_IF для целочисленных - for _, typ := range append(unsignedTypes, signedTypes...) { - funcs = append(funcs, &catalog.Function{ - Name: "AVG_IF", +func stddevVarianceFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "STDDEV", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, ReturnTypeNullable: true, - }) - } - - // AVG_IF для float/double - for _, typ := range []string{"float", "double"} { - funcs = append(funcs, &catalog.Function{ - Name: "AVG_IF", + }, + { + Name: "STDDEV_POPULATION", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Double"}}, }, - ReturnType: &ast.TypeName{Name: typ}, + ReturnType: &ast.TypeName{Name: "Double"}, ReturnTypeNullable: true, - }) - } - - // SOME - for _, typ := range types { - funcs = append(funcs, &catalog.Function{ - Name: "SOME", + }, + { + Name: "POPULATION_STDDEV", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "Double"}}, }, - ReturnType: &ast.TypeName{Name: typ}, + ReturnType: &ast.TypeName{Name: "Double"}, ReturnTypeNullable: true, - }) - } - - // AGGREGATE_LIST и AGGREGATE_LIST_DISTINCT - for _, typ := range types { - funcs = append(funcs, &catalog.Function{ - Name: "AGGREGATE_LIST", + }, + { + Name: "STDDEV_SAMPLE", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "Double"}}, }, - ReturnType: &ast.TypeName{Name: "List<" + typ + ">"}, - }) - funcs = append(funcs, &catalog.Function{ - Name: "AGGREGATE_LIST_DISTINCT", + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }, + { + Name: "STDDEVSAMP", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "Double"}}, }, - ReturnType: &ast.TypeName{Name: "List<" + typ + ">"}, - }) - } - - // BOOL_AND, BOOL_OR, BOOL_XOR - boolAggrs := []string{"BOOL_AND", "BOOL_OR", "BOOL_XOR"} - for _, name := range boolAggrs { - funcs = append(funcs, &catalog.Function{ - Name: name, + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }, + { + Name: "VARIANCE", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Double"}}, }, - ReturnType: &ast.TypeName{Name: "Bool"}, + ReturnType: &ast.TypeName{Name: "Double"}, ReturnTypeNullable: true, - }) - } - - // BIT_AND, BIT_OR, BIT_XOR - bitAggrs := []string{"BIT_AND", "BIT_OR", "BIT_XOR"} - for _, typ := range append(unsignedTypes, signedTypes...) { - for _, name := range bitAggrs { - funcs = append(funcs, &catalog.Function{ - Name: name, - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - }, - ReturnType: &ast.TypeName{Name: typ}, - ReturnTypeNullable: true, - }) - } - } - - // STDDEV и VARIANCE - stdDevVariants := []struct { - name string - returnType string - }{ - {"STDDEV", "Double"}, - {"VARIANCE", "Double"}, - {"STDDEV_SAMPLE", "Double"}, - {"VARIANCE_SAMPLE", "Double"}, - {"STDDEV_POPULATION", "Double"}, - {"VARIANCE_POPULATION", "Double"}, - } - for _, variant := range stdDevVariants { - funcs = append(funcs, &catalog.Function{ - Name: variant.name, + }, + { + Name: "VARIANCE_POPULATION", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, - ReturnType: &ast.TypeName{Name: variant.returnType}, + ReturnType: &ast.TypeName{Name: "Double"}, ReturnTypeNullable: true, - }) + }, + { + Name: "POPULATION_VARIANCE", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }, + { + Name: "VARPOP", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }, + { + Name: "VARIANCE_SAMPLE", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }, } +} - // CORRELATION и COVARIANCE - corrCovar := []string{"CORRELATION", "COVARIANCE", "COVARIANCE_SAMPLE", "COVARIANCE_POPULATION"} - for _, name := range corrCovar { - funcs = append(funcs, &catalog.Function{ - Name: name, +func correlationCovarianceFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "CORRELATION", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }, + { + Name: "COVARIANCE", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }, + { + Name: "COVARIANCE_SAMPLE", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, ReturnTypeNullable: true, - }) + }, + { + Name: "COVARIANCE_POPULATION", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }, } +} - // HISTOGRAM - funcs = append(funcs, &catalog.Function{ - Name: "HISTOGRAM", - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: "Double"}}, - }, - ReturnType: &ast.TypeName{Name: "HistogramStruct"}, - ReturnTypeNullable: true, - }) - - // TOP и BOTTOM - topBottom := []string{"TOP", "BOTTOM"} - for _, name := range topBottom { - for _, typ := range types { - funcs = append(funcs, &catalog.Function{ - Name: name, - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: "Uint32"}}, - }, - ReturnType: &ast.TypeName{Name: "List<" + typ + ">"}, - }) - } +func percentileMedianFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "PERCENTILE", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "MEDIAN", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "MEDIAN", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, } +} - // MAX_BY и MIN_BY - minMaxBy := []string{"MAX_BY", "MIN_BY"} - for _, name := range minMaxBy { - for _, typ := range types { - funcs = append(funcs, &catalog.Function{ - Name: name, - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: "any"}}, - }, - ReturnType: &ast.TypeName{Name: typ}, - ReturnTypeNullable: true, - }) - } +func boolAndOrXorFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "BOOL_AND", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + ReturnTypeNullable: true, + }, + { + Name: "BOOL_OR", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + ReturnTypeNullable: true, + }, + { + Name: "BOOL_XOR", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + ReturnTypeNullable: true, + }, } +} - // ... (добавьте другие агрегатные функции по аналогии) - - return funcs +func bitAndOrXorFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "BIT_AND", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "BIT_OR", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "BIT_XOR", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } } diff --git a/internal/engine/ydb/lib/basic.go b/internal/engine/ydb/lib/basic.go index 08c0011787..d5cbfda950 100644 --- a/internal/engine/ydb/lib/basic.go +++ b/internal/engine/ydb/lib/basic.go @@ -5,199 +5,709 @@ import ( "github.com/sqlc-dev/sqlc/internal/sql/catalog" ) -var types = []string{ - "bool", - "int8", "int16", "int32", "int64", - "uint8", "uint16", "uint32", "uint64", - "float", "double", - "string", "utf8", - "any", -} - -var ( - unsignedTypes = []string{"uint8", "uint16", "uint32", "uint64"} - signedTypes = []string{"int8", "int16", "int32", "int64"} - numericTypes = append(append(unsignedTypes, signedTypes...), "float", "double") -) - func BasicFunctions() []*catalog.Function { var funcs []*catalog.Function - for _, typ := range types { - // COALESCE, NVL - funcs = append(funcs, &catalog.Function{ - Name: "COALESCE", + funcs = append(funcs, lengthFuncs()...) + funcs = append(funcs, substringFuncs()...) + funcs = append(funcs, findFuncs()...) + funcs = append(funcs, rfindFuncs()...) + funcs = append(funcs, startsWithFuncs()...) + funcs = append(funcs, endsWithFuncs()...) + funcs = append(funcs, ifFuncs()...) + funcs = append(funcs, nanvlFuncs()...) + funcs = append(funcs, randomFuncs()...) + funcs = append(funcs, currentUtcFuncs()...) + funcs = append(funcs, currentTzFuncs()...) + funcs = append(funcs, addTimezoneFuncs()...) + funcs = append(funcs, removeTimezoneFuncs()...) + funcs = append(funcs, versionFuncs()...) + funcs = append(funcs, ensureFuncs()...) + funcs = append(funcs, assumeStrictFuncs()...) + funcs = append(funcs, likelyFuncs()...) + funcs = append(funcs, evaluateFuncs()...) + funcs = append(funcs, simpleTypesLiteralsFuncs()...) + funcs = append(funcs, toFromBytesFuncs()...) + funcs = append(funcs, byteAtFuncs()...) + funcs = append(funcs, testClearSetFlipBitFuncs()...) + funcs = append(funcs, absFuncs()...) + funcs = append(funcs, justUnwrapNothingFuncs()...) + funcs = append(funcs, pickleUnpickleFuncs()...) + + // todo: implement functions: + // Udf, AsTuple, AsStruct, AsList, AsDict, AsSet, AsListStrict, AsDictStrict, AsSetStrict, + // Variant, AsVariant, Visit, VisitOrDefault, VariantItem, Way, DynamicVariant, + // Enum, AsEnum, AsTagged, Untag, TableRow, Callable, + // StaticMap, StaticZip, StaticFold, StaticFold1, + // AggregationFactory, AggregateTransformInput, AggregateTransformOutput, AggregateFlatten + + return funcs +} + +func lengthFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "LENGTH", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + { + Name: "LEN", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + } +} + +func substringFuncs() []*catalog.Function { + funcs := []*catalog.Function{ + { + Name: "Substring", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "Substring", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + } + return funcs +} + +func findFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Find", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + { + Name: "Find", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + } +} + +func rfindFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "RFind", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + { + Name: "RFind", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + } +} + +func startsWithFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "StartsWith", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} + +func endsWithFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "EndsWith", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} + +func ifFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "IF", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "IF", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: false, + }, + } +} + +func nanvlFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "NANVL", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } +} + +func randomFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Random", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}, + Mode: ast.FuncParamVariadic, + }, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "RandomNumber", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}, + Mode: ast.FuncParamVariadic, + }, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "RandomUuid", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}, + Mode: ast.FuncParamVariadic, + }, + }, + ReturnType: &ast.TypeName{Name: "Uuid"}, + }, + } +} + +func currentUtcFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "CurrentUtcDate", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: typ}}, { - Type: &ast.TypeName{Name: typ}, + Type: &ast.TypeName{Name: "any"}, Mode: ast.FuncParamVariadic, }, }, - ReturnType: &ast.TypeName{Name: typ}, - ReturnTypeNullable: false, - }) - funcs = append(funcs, &catalog.Function{ - Name: "NVL", + ReturnType: &ast.TypeName{Name: "Date"}, + }, + { + Name: "CurrentUtcDatetime", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: typ}}, { - Type: &ast.TypeName{Name: typ}, + Type: &ast.TypeName{Name: "any"}, Mode: ast.FuncParamVariadic, }, }, - ReturnType: &ast.TypeName{Name: typ}, - ReturnTypeNullable: false, - }) + ReturnType: &ast.TypeName{Name: "Datetime"}, + }, + { + Name: "CurrentUtcTimestamp", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + Mode: ast.FuncParamVariadic, + }, + }, + ReturnType: &ast.TypeName{Name: "Timestamp"}, + }, + } +} - // IF(Bool, T, T) -> T - funcs = append(funcs, &catalog.Function{ - Name: "IF", +func currentTzFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "CurrentTzDate", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + { + Type: &ast.TypeName{Name: "any"}, + Mode: ast.FuncParamVariadic, + }, + }, + ReturnType: &ast.TypeName{Name: "TzDate"}, + }, + { + Name: "CurrentTzDatetime", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + { + Type: &ast.TypeName{Name: "any"}, + Mode: ast.FuncParamVariadic, + }, + }, + ReturnType: &ast.TypeName{Name: "TzDatetime"}, + }, + { + Name: "CurrentTzTimestamp", Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + { + Type: &ast.TypeName{Name: "any"}, + Mode: ast.FuncParamVariadic, + }, + }, + ReturnType: &ast.TypeName{Name: "TzTimestamp"}, + }, + } +} + +func addTimezoneFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "AddTimezone", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func removeTimezoneFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "RemoveTimezone", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func versionFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Version", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "String"}, + }, + } +} + +func ensureFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Ensure", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "Bool"}}, - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "String"}}, }, - ReturnType: &ast.TypeName{Name: typ}, - ReturnTypeNullable: false, - }) + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "EnsureType", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "EnsureConvertibleTo", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} - // LENGTH, LEN - funcs = append(funcs, &catalog.Function{ - Name: "LENGTH", +func assumeStrictFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "AssumeStrict", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "any"}}, }, - ReturnType: &ast.TypeName{Name: "Uint32"}, - ReturnTypeNullable: true, - }) - funcs = append(funcs, &catalog.Function{ - Name: "LEN", + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func likelyFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Likely", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "any"}}, }, - ReturnType: &ast.TypeName{Name: "Uint32"}, - ReturnTypeNullable: true, - }) + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} - // StartsWith, EndsWith - funcs = append(funcs, &catalog.Function{ - Name: "StartsWith", +func evaluateFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "EvaluateExpr", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "EvaluateAtom", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func simpleTypesLiteralsFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Bool", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "Bool"}, - }) - funcs = append(funcs, &catalog.Function{ - Name: "EndsWith", + }, + { + Name: "Uint8", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint8"}, + }, + { + Name: "Int32", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Int32"}, + }, + { + Name: "Uint32", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + { + Name: "Int64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Int64"}, + }, + { + Name: "Uint64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "Float", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Float"}, + }, + { + Name: "Double", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Decimal", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint8"}}, // precision + {Type: &ast.TypeName{Name: "Uint8"}}, // scale + }, + ReturnType: &ast.TypeName{Name: "Decimal"}, + }, + { + Name: "String", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "Utf8", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Yson", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Yson"}, + }, + { + Name: "Json", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Json"}, + }, + { + Name: "Date", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Date"}, + }, + { + Name: "Datetime", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Datetime"}, + }, + { + Name: "Timestamp", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Timestamp"}, + }, + { + Name: "Interval", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval"}, + }, + { + Name: "TzDate", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "TzDate"}, + }, + { + Name: "TzDatetime", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "TzDatetime"}, + }, + { + Name: "TzTimestamp", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "TzTimestamp"}, + }, + { + Name: "Uuid", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uuid"}, + }, + } +} + +func toFromBytesFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "ToBytes", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "FromBytes", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func byteAtFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "ByteAt", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint8"}, + }, + } +} + +func testClearSetFlipBitFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "TestBit", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Uint8"}}, }, ReturnType: &ast.TypeName{Name: "Bool"}, - }) - - // ABS(T) -> T - } - - // SUBSTRING - funcs = append(funcs, &catalog.Function{ - Name: "Substring", - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: "String"}}, - }, - ReturnType: &ast.TypeName{Name: "String"}, - }) - funcs = append(funcs, &catalog.Function{ - Name: "Substring", - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: "String"}}, - {Type: &ast.TypeName{Name: "Uint32"}}, - }, - ReturnType: &ast.TypeName{Name: "String"}, - }) - funcs = append(funcs, &catalog.Function{ - Name: "Substring", - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: "String"}}, - {Type: &ast.TypeName{Name: "Uint32"}}, - {Type: &ast.TypeName{Name: "Uint32"}}, - }, - ReturnType: &ast.TypeName{Name: "String"}, - }) - - // FIND / RFIND - for _, name := range []string{"FIND", "RFIND"} { - for _, typ := range []string{"String", "Utf8"} { - funcs = append(funcs, &catalog.Function{ - Name: name, - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: typ}}, - }, - ReturnType: &ast.TypeName{Name: "Uint32"}, - }) - funcs = append(funcs, &catalog.Function{ - Name: name, - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: "Uint32"}}, - }, - ReturnType: &ast.TypeName{Name: "Uint32"}, - }) - } + }, + { + Name: "ClearBit", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Uint8"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "SetBit", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Uint8"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "FlipBit", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Uint8"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, } +} - for _, typ := range numericTypes { - funcs = append(funcs, &catalog.Function{ +func absFuncs() []*catalog.Function { + return []*catalog.Function{ + { Name: "Abs", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - }, - ReturnType: &ast.TypeName{Name: typ}, - }) - } - - // NANVL - funcs = append(funcs, &catalog.Function{ - Name: "NANVL", - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: "Float"}}, - {Type: &ast.TypeName{Name: "Float"}}, - }, - ReturnType: &ast.TypeName{Name: "Float"}, - }) - funcs = append(funcs, &catalog.Function{ - Name: "NANVL", - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: "Double"}}, - {Type: &ast.TypeName{Name: "Double"}}, - }, - ReturnType: &ast.TypeName{Name: "Double"}, - }) - - // Random* - funcs = append(funcs, &catalog.Function{ - Name: "Random", - Args: []*catalog.Argument{}, - ReturnType: &ast.TypeName{Name: "Double"}, - }) - funcs = append(funcs, &catalog.Function{ - Name: "RandomNumber", - Args: []*catalog.Argument{}, - ReturnType: &ast.TypeName{Name: "Uint64"}, - }) - funcs = append(funcs, &catalog.Function{ - Name: "RandomUuid", - Args: []*catalog.Argument{}, - ReturnType: &ast.TypeName{Name: "Uuid"}, - }) - - // todo: add all remain functions + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} - return funcs +func justUnwrapNothingFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Just", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "Unwrap", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Unwrap", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Nothing", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } +} + +func pickleUnpickleFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Pickle", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "StablePickle", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "Unpickle", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } } diff --git a/internal/engine/ydb/lib/cpp.go b/internal/engine/ydb/lib/cpp.go new file mode 100644 index 0000000000..9f076aba98 --- /dev/null +++ b/internal/engine/ydb/lib/cpp.go @@ -0,0 +1,27 @@ +package lib + +import ( + "github.com/sqlc-dev/sqlc/internal/engine/ydb/lib/cpp" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func CppFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, cpp.DateTimeFunctions()...) + funcs = append(funcs, cpp.DigestFunctions()...) + funcs = append(funcs, cpp.HyperscanFunctions()...) + funcs = append(funcs, cpp.IpFunctions()...) + funcs = append(funcs, cpp.MathFunctions()...) + funcs = append(funcs, cpp.PcreFunctions()...) + funcs = append(funcs, cpp.PireFunctions()...) + funcs = append(funcs, cpp.Re2Functions()...) + funcs = append(funcs, cpp.StringFunctions()...) + funcs = append(funcs, cpp.UnicodeFunctions()...) + funcs = append(funcs, cpp.UrlFunctions()...) + funcs = append(funcs, cpp.YsonFunctions()...) + + // TODO: Histogram library, KNN library, PostgeSQL library + + return funcs +} diff --git a/internal/engine/ydb/lib/cpp/datetime.go b/internal/engine/ydb/lib/cpp/datetime.go new file mode 100644 index 0000000000..ca6f6bc6b6 --- /dev/null +++ b/internal/engine/ydb/lib/cpp/datetime.go @@ -0,0 +1,695 @@ +package cpp + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func DateTimeFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, dateTimeMakeFuncs()...) + funcs = append(funcs, dateTimeGetFuncs()...) + funcs = append(funcs, dateTimeUpdateFuncs()...) + funcs = append(funcs, dateTimeFromFuncs()...) + funcs = append(funcs, dateTimeToFuncs()...) + funcs = append(funcs, dateTimeIntervalFuncs()...) + funcs = append(funcs, dateTimeStartEndFuncs()...) + funcs = append(funcs, dateTimeFormatFuncs()...) + funcs = append(funcs, dateTimeParseFuncs()...) + + return funcs +} + +func dateTimeMakeFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "DateTime::MakeDate", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Date"}, + }, + { + Name: "DateTime::MakeDate32", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Date32"}, + }, + { + Name: "DateTime::MakeTzDate32", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "TzDate32"}, + }, + { + Name: "DateTime::MakeDatetime", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Datetime"}, + }, + { + Name: "DateTime::MakeTzDatetime", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "TzDatetime"}, + }, + { + Name: "DateTime::MakeDatetime64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Datetime64"}, + }, + { + Name: "DateTime::MakeTzDatetime64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "TzDatetime64"}, + }, + { + Name: "DateTime::MakeTimestamp", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Timestamp"}, + }, + { + Name: "DateTime::MakeTzTimestamp", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "TzTimestamp"}, + }, + { + Name: "DateTime::MakeTimestamp64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Timestamp64"}, + }, + { + Name: "DateTime::MakeTzTimestamp64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "TzTimestamp64"}, + }, + } +} + +func dateTimeGetFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "DateTime::GetYear", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint16"}, + }, + { + Name: "DateTime::GetYear", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Int32"}, + }, + { + Name: "DateTime::GetDayOfYear", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint16"}, + }, + { + Name: "DateTime::GetMonth", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint8"}, + }, + { + Name: "DateTime::GetMonthName", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "DateTime::GetWeekOfYear", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint8"}, + }, + { + Name: "DateTime::GetWeekOfYearIso8601", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint8"}, + }, + { + Name: "DateTime::GetDayOfMonth", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint8"}, + }, + { + Name: "DateTime::GetDayOfWeek", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint8"}, + }, + { + Name: "DateTime::GetDayOfWeekName", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "DateTime::GetHour", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint8"}, + }, + { + Name: "DateTime::GetMinute", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint8"}, + }, + { + Name: "DateTime::GetSecond", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint8"}, + }, + { + Name: "DateTime::GetMillisecondOfSecond", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + { + Name: "DateTime::GetMicrosecondOfSecond", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + { + Name: "DateTime::GetTimezoneId", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint16"}, + }, + { + Name: "DateTime::GetTimezoneName", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + } +} + +func dateTimeUpdateFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "DateTime::Update", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::Update", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::Update", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::Update", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::Update", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::Update", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::Update", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::Update", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } +} + +func dateTimeFromFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "DateTime::FromSeconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "Timestamp"}, + }, + { + Name: "DateTime::FromSeconds64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Timestamp64"}, + }, + { + Name: "DateTime::FromMilliseconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "Timestamp"}, + }, + { + Name: "DateTime::FromMilliseconds64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Timestamp64"}, + }, + { + Name: "DateTime::FromMicroseconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "Timestamp"}, + }, + { + Name: "DateTime::FromMicroseconds64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Timestamp64"}, + }, + } +} + +func dateTimeToFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "DateTime::ToSeconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "DateTime::ToMilliseconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "DateTime::ToMicroseconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func dateTimeIntervalFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "DateTime::ToDays", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "DateTime::ToHours", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "DateTime::ToMinutes", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "DateTime::ToSeconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "DateTime::ToMilliseconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "DateTime::ToMicroseconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "DateTime::IntervalFromDays", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int32"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval"}, + }, + { + Name: "DateTime::Interval64FromDays", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int32"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval64"}, + }, + { + Name: "DateTime::IntervalFromHours", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int32"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval"}, + }, + { + Name: "DateTime::Interval64FromHours", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval64"}, + }, + { + Name: "DateTime::IntervalFromMinutes", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int32"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval"}, + }, + { + Name: "DateTime::Interval64FromMinutes", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval64"}, + }, + { + Name: "DateTime::IntervalFromSeconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval"}, + }, + { + Name: "DateTime::Interval64FromSeconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval64"}, + }, + { + Name: "DateTime::IntervalFromMilliseconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval"}, + }, + { + Name: "DateTime::Interval64FromMilliseconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval64"}, + }, + { + Name: "DateTime::IntervalFromMicroseconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval"}, + }, + { + Name: "DateTime::Interval64FromMicroseconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval64"}, + }, + } +} + +func dateTimeStartEndFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "DateTime::StartOfYear", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::EndOfYear", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::StartOfQuarter", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::EndOfQuarter", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::StartOfMonth", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::EndOfMonth", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::StartOfWeek", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::EndOfWeek", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::StartOfDay", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::EndOfDay", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::StartOf", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::EndOf", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } +} + +func dateTimeFormatFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "DateTime::Format", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func dateTimeParseFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "DateTime::Parse", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "DateTime::Parse64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "DateTime::ParseRfc822", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::ParseIso8601", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::ParseHttp", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::ParseX509", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } +} diff --git a/internal/engine/ydb/lib/cpp/digest.go b/internal/engine/ydb/lib/cpp/digest.go new file mode 100644 index 0000000000..dccdb8509b --- /dev/null +++ b/internal/engine/ydb/lib/cpp/digest.go @@ -0,0 +1,171 @@ +package cpp + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func DigestFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, digestCrcFuncs()...) + funcs = append(funcs, digestFnvFuncs()...) + funcs = append(funcs, digestMurmurFuncs()...) + funcs = append(funcs, digestCityFuncs()...) + + return funcs +} + +func digestCrcFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Digest::Crc32c", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + { + Name: "Digest::Crc64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "Digest::Crc64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + } +} + +func digestFnvFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Digest::Fnv32", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + { + Name: "Digest::Fnv32", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + { + Name: "Digest::Fnv64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "Digest::Fnv64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + } +} + +func digestMurmurFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Digest::MurMurHash", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "Digest::MurMurHash", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "Digest::MurMurHash32", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + { + Name: "Digest::MurMurHash32", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + { + Name: "Digest::MurMurHash2A", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "Digest::MurMurHash2A", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "Digest::MurMurHash2A32", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + { + Name: "Digest::MurMurHash2A32", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + } +} + +func digestCityFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Digest::CityHash", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "Digest::CityHash", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "Digest::CityHash128", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} diff --git a/internal/engine/ydb/lib/cpp/hyperscan.go b/internal/engine/ydb/lib/cpp/hyperscan.go new file mode 100644 index 0000000000..be3aa968e2 --- /dev/null +++ b/internal/engine/ydb/lib/cpp/hyperscan.go @@ -0,0 +1,105 @@ +package cpp + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func HyperscanFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, hyperscanGrepFuncs()...) + funcs = append(funcs, hyperscanMatchFuncs()...) + funcs = append(funcs, hyperscanBacktrackingFuncs()...) + funcs = append(funcs, hyperscanMultiFuncs()...) + funcs = append(funcs, hyperscanCaptureFuncs()...) + funcs = append(funcs, hyperscanReplaceFuncs()...) + + return funcs +} + +func hyperscanGrepFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Hyperscan::Grep", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func hyperscanMatchFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Hyperscan::Match", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func hyperscanBacktrackingFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Hyperscan::BacktrackingGrep", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Hyperscan::BacktrackingMatch", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func hyperscanMultiFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Hyperscan::MultiGrep", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Hyperscan::MultiMatch", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func hyperscanCaptureFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Hyperscan::Capture", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func hyperscanReplaceFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Hyperscan::Replace", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} diff --git a/internal/engine/ydb/lib/cpp/ip.go b/internal/engine/ydb/lib/cpp/ip.go new file mode 100644 index 0000000000..a644da910c --- /dev/null +++ b/internal/engine/ydb/lib/cpp/ip.go @@ -0,0 +1,140 @@ +package cpp + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func IpFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, ipFromStringFuncs()...) + funcs = append(funcs, ipToStringFuncs()...) + funcs = append(funcs, ipCheckFuncs()...) + funcs = append(funcs, ipConvertFuncs()...) + funcs = append(funcs, ipSubnetFuncs()...) + funcs = append(funcs, ipMatchFuncs()...) + + return funcs +} + +func ipFromStringFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Ip::FromString", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Ip::SubnetFromString", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + } +} + +func ipToStringFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Ip::ToString", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Ip::ToString", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + } +} + +func ipCheckFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Ip::IsIPv4", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Ip::IsIPv6", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Ip::IsEmbeddedIPv4", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} + +func ipConvertFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Ip::ConvertToIPv6", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + } +} + +func ipSubnetFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Ip::GetSubnet", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "Ip::GetSubnet", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint8"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "Ip::GetSubnetByMask", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + } +} + +func ipMatchFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Ip::SubnetMatch", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} diff --git a/internal/engine/ydb/lib/cpp/math.go b/internal/engine/ydb/lib/cpp/math.go new file mode 100644 index 0000000000..288464ad0d --- /dev/null +++ b/internal/engine/ydb/lib/cpp/math.go @@ -0,0 +1,439 @@ +package cpp + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func MathFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, mathConstantsFuncs()...) + funcs = append(funcs, mathCheckFuncs()...) + funcs = append(funcs, mathUnaryFuncs()...) + funcs = append(funcs, mathBinaryFuncs()...) + funcs = append(funcs, mathLdexpFuncs()...) + funcs = append(funcs, mathRoundFuncs()...) + funcs = append(funcs, mathFuzzyEqualsFuncs()...) + funcs = append(funcs, mathModRemFuncs()...) + funcs = append(funcs, mathRoundingModeFuncs()...) + funcs = append(funcs, mathNearbyIntFuncs()...) + + return funcs +} + +func mathConstantsFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Math::Pi", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::E", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Eps", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + } +} + +func mathCheckFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Math::IsInf", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Math::IsNaN", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Math::IsFinite", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} + +func mathUnaryFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Math::Abs", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Acos", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Asin", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Asinh", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Atan", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Cbrt", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Ceil", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Cos", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Cosh", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Erf", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::ErfInv", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::ErfcInv", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Exp", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Exp2", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Fabs", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Floor", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Lgamma", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Rint", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Sigmoid", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Sin", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Sinh", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Sqrt", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Tan", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Tanh", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Tgamma", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Trunc", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Log", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Log2", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Log10", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + } +} + +func mathBinaryFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Math::Atan2", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Fmod", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Hypot", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Pow", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Remainder", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + } +} + +func mathLdexpFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Math::Ldexp", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Int32"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + } +} + +func mathRoundFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Math::Round", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Round", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Int32"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + } +} + +func mathFuzzyEqualsFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Math::FuzzyEquals", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Math::FuzzyEquals", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} + +func mathModRemFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Math::Mod", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Int64"}, + ReturnTypeNullable: true, + }, + { + Name: "Math::Rem", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Int64"}, + ReturnTypeNullable: true, + }, + } +} + +func mathRoundingModeFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Math::RoundDownward", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Math::RoundToNearest", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Math::RoundTowardZero", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Math::RoundUpward", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func mathNearbyIntFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Math::NearbyInt", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Int64"}, + ReturnTypeNullable: true, + }, + } +} diff --git a/internal/engine/ydb/lib/cpp/pcre.go b/internal/engine/ydb/lib/cpp/pcre.go new file mode 100644 index 0000000000..4b313ff80f --- /dev/null +++ b/internal/engine/ydb/lib/cpp/pcre.go @@ -0,0 +1,105 @@ +package cpp + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func PcreFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, pcreGrepFuncs()...) + funcs = append(funcs, pcreMatchFuncs()...) + funcs = append(funcs, pcreBacktrackingFuncs()...) + funcs = append(funcs, pcreMultiFuncs()...) + funcs = append(funcs, pcreCaptureFuncs()...) + funcs = append(funcs, pcreReplaceFuncs()...) + + return funcs +} + +func pcreGrepFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Pcre::Grep", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func pcreMatchFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Pcre::Match", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func pcreBacktrackingFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Pcre::BacktrackingGrep", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Pcre::BacktrackingMatch", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func pcreMultiFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Pcre::MultiGrep", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Pcre::MultiMatch", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func pcreCaptureFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Pcre::Capture", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func pcreReplaceFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Pcre::Replace", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} diff --git a/internal/engine/ydb/lib/cpp/pire.go b/internal/engine/ydb/lib/cpp/pire.go new file mode 100644 index 0000000000..ae7eece256 --- /dev/null +++ b/internal/engine/ydb/lib/cpp/pire.go @@ -0,0 +1,85 @@ +package cpp + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func PireFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, pireGrepFuncs()...) + funcs = append(funcs, pireMatchFuncs()...) + funcs = append(funcs, pireMultiFuncs()...) + funcs = append(funcs, pireCaptureFuncs()...) + funcs = append(funcs, pireReplaceFuncs()...) + + return funcs +} + +func pireGrepFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Pire::Grep", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func pireMatchFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Pire::Match", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func pireMultiFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Pire::MultiGrep", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Pire::MultiMatch", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func pireCaptureFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Pire::Capture", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func pireReplaceFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Pire::Replace", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} diff --git a/internal/engine/ydb/lib/cpp/re2.go b/internal/engine/ydb/lib/cpp/re2.go new file mode 100644 index 0000000000..667c0f57e0 --- /dev/null +++ b/internal/engine/ydb/lib/cpp/re2.go @@ -0,0 +1,319 @@ +package cpp + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func Re2Functions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, re2GrepFuncs()...) + funcs = append(funcs, re2MatchFuncs()...) + funcs = append(funcs, re2CaptureFuncs()...) + funcs = append(funcs, re2FindAndConsumeFuncs()...) + funcs = append(funcs, re2ReplaceFuncs()...) + funcs = append(funcs, re2CountFuncs()...) + funcs = append(funcs, re2OptionsFuncs()...) + + return funcs +} + +func re2GrepFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Re2::Grep", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Grep", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func re2MatchFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Re2::Match", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Match", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func re2CaptureFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Re2::Capture", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Capture", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func re2FindAndConsumeFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Re2::FindAndConsume", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::FindAndConsume", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func re2ReplaceFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Re2::Replace", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Replace", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func re2CountFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Re2::Count", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Count", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func re2OptionsFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Re2::Options", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} diff --git a/internal/engine/ydb/lib/cpp/string.go b/internal/engine/ydb/lib/cpp/string.go new file mode 100644 index 0000000000..291dd10eec --- /dev/null +++ b/internal/engine/ydb/lib/cpp/string.go @@ -0,0 +1,152 @@ +package cpp + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func StringFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, stringBase32Funcs()...) + funcs = append(funcs, stringBase64Funcs()...) + funcs = append(funcs, stringEscapeFuncs()...) + funcs = append(funcs, stringHexFuncs()...) + funcs = append(funcs, stringHtmlFuncs()...) + funcs = append(funcs, stringCgiFuncs()...) + + return funcs +} + +func stringBase32Funcs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "String::Base32Encode", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "String::Base32Decode", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "String::Base32StrictDecode", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + } +} + +func stringBase64Funcs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "String::Base64Encode", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "String::Base64Decode", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "String::Base64StrictDecode", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + } +} + +func stringEscapeFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "String::EscapeC", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "String::UnescapeC", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + } +} + +func stringHexFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "String::HexEncode", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "String::HexDecode", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + } +} + +func stringHtmlFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "String::EncodeHtml", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "String::DecodeHtml", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + } +} + +func stringCgiFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "String::CgiEscape", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "String::CgiUnescape", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + } +} diff --git a/internal/engine/ydb/lib/cpp/unicode.go b/internal/engine/ydb/lib/cpp/unicode.go new file mode 100644 index 0000000000..e8c967020d --- /dev/null +++ b/internal/engine/ydb/lib/cpp/unicode.go @@ -0,0 +1,532 @@ +package cpp + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func UnicodeFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, unicodeCheckFuncs()...) + funcs = append(funcs, unicodeLengthFuncs()...) + funcs = append(funcs, unicodeFindFuncs()...) + funcs = append(funcs, unicodeSubstringFuncs()...) + funcs = append(funcs, unicodeNormalizeFuncs()...) + funcs = append(funcs, unicodeTranslitFuncs()...) + funcs = append(funcs, unicodeLevensteinFuncs()...) + funcs = append(funcs, unicodeFoldFuncs()...) + funcs = append(funcs, unicodeReplaceFuncs()...) + funcs = append(funcs, unicodeRemoveFuncs()...) + funcs = append(funcs, unicodeCodePointFuncs()...) + funcs = append(funcs, unicodeReverseFuncs()...) + funcs = append(funcs, unicodeCaseFuncs()...) + funcs = append(funcs, unicodeSplitJoinFuncs()...) + funcs = append(funcs, unicodeToUint64Funcs()...) + funcs = append(funcs, unicodeStripFuncs()...) + funcs = append(funcs, unicodeIsFuncs()...) + funcs = append(funcs, unicodeIsUnicodeSetFuncs()...) + + return funcs +} + +func unicodeCheckFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::IsUtf", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} + +func unicodeLengthFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::GetLength", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + } +} + +func unicodeFindFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::Find", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }, + { + Name: "Unicode::Find", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }, + { + Name: "Unicode::RFind", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }, + { + Name: "Unicode::RFind", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }, + } +} + +func unicodeSubstringFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::Substring", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + } +} + +func unicodeNormalizeFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::Normalize", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::NormalizeNFD", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::NormalizeNFC", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::NormalizeNFKD", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::NormalizeNFKC", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + } +} + +func unicodeTranslitFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::Translit", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::Translit", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + } +} + +func unicodeLevensteinFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::LevensteinDistance", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + } +} + +func unicodeFoldFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::Fold", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::Fold", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::Fold", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::Fold", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::Fold", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::Fold", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + } +} + +func unicodeReplaceFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::ReplaceAll", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::ReplaceFirst", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::ReplaceLast", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + } +} + +func unicodeRemoveFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::RemoveAll", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::RemoveFirst", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::RemoveLast", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + } +} + +func unicodeCodePointFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::ToCodePointList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Unicode::FromCodePointList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + } +} + +func unicodeReverseFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::Reverse", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + } +} + +func unicodeCaseFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::ToLower", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::ToUpper", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::ToTitle", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + } +} + +func unicodeSplitJoinFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::SplitToList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Unicode::SplitToList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Unicode::SplitToList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Unicode::SplitToList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Unicode::JoinFromList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + } +} + +func unicodeToUint64Funcs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::ToUint64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "Unicode::ToUint64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Uint16"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "Unicode::TryToUint64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }, + { + Name: "Unicode::TryToUint64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Uint16"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }, + } +} + +func unicodeStripFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::Strip", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + } +} + +func unicodeIsFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::IsAscii", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Unicode::IsSpace", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Unicode::IsUpper", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Unicode::IsLower", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Unicode::IsAlpha", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Unicode::IsAlnum", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Unicode::IsHex", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} + +func unicodeIsUnicodeSetFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::IsUnicodeSet", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} diff --git a/internal/engine/ydb/lib/cpp/url.go b/internal/engine/ydb/lib/cpp/url.go new file mode 100644 index 0000000000..151115a8f0 --- /dev/null +++ b/internal/engine/ydb/lib/cpp/url.go @@ -0,0 +1,413 @@ +package cpp + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func UrlFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, urlNormalizeFuncs()...) + funcs = append(funcs, urlEncodeDecodeFuncs()...) + funcs = append(funcs, urlParseFuncs()...) + funcs = append(funcs, urlGetFuncs()...) + funcs = append(funcs, urlDomainFuncs()...) + funcs = append(funcs, urlCutFuncs()...) + funcs = append(funcs, urlPunycodeFuncs()...) + funcs = append(funcs, urlQueryStringFuncs()...) + + return funcs +} + +func urlNormalizeFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Url::Normalize", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::NormalizeWithDefaultHttpScheme", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + } +} + +func urlEncodeDecodeFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Url::Encode", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::Decode", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + } +} + +func urlParseFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Url::Parse", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func urlGetFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Url::GetScheme", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "Url::GetHost", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::GetHostPort", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::GetSchemeHost", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::GetSchemeHostPort", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::GetPort", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::GetTail", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::GetPath", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::GetFragment", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::GetCGIParam", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::GetDomain", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint8"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + } +} + +func urlDomainFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Url::GetTLD", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "Url::IsKnownTLD", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Url::IsWellKnownTLD", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Url::GetDomainLevel", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "Url::GetSignificantDomain", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "Url::GetSignificantDomain", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "Url::GetOwner", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + } +} + +func urlCutFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Url::CutScheme", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::CutWWW", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::CutWWW2", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::CutQueryStringAndFragment", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + } +} + +func urlPunycodeFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Url::HostNameToPunycode", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::ForceHostNameToPunycode", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "Url::PunycodeToHostName", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::ForcePunycodeToHostName", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "Url::CanBePunycodeHostName", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} + +func urlQueryStringFuncs() []*catalog.Function { + // fixme: rewrite with containers if possible + return []*catalog.Function{ + { + Name: "Url::QueryStringToList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Url::QueryStringToList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Url::QueryStringToList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Url::QueryStringToList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Url::QueryStringToList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Url::QueryStringToDict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Url::QueryStringToDict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Url::QueryStringToDict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Url::QueryStringToDict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Url::QueryStringToDict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Url::BuildQueryString", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "Url::BuildQueryString", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + } +} diff --git a/internal/engine/ydb/lib/cpp/yson.go b/internal/engine/ydb/lib/cpp/yson.go new file mode 100644 index 0000000000..78332e0f29 --- /dev/null +++ b/internal/engine/ydb/lib/cpp/yson.go @@ -0,0 +1,632 @@ +package cpp + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func YsonFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, ysonParseFuncs()...) + funcs = append(funcs, ysonFromFuncs()...) + funcs = append(funcs, ysonWithAttributesFuncs()...) + funcs = append(funcs, ysonEqualsFuncs()...) + funcs = append(funcs, ysonGetHashFuncs()...) + funcs = append(funcs, ysonIsFuncs()...) + funcs = append(funcs, ysonGetLengthFuncs()...) + funcs = append(funcs, ysonConvertToFuncs()...) + funcs = append(funcs, ysonConvertToListFuncs()...) + funcs = append(funcs, ysonConvertToDictFuncs()...) + funcs = append(funcs, ysonContainsFuncs()...) + funcs = append(funcs, ysonLookupFuncs()...) + funcs = append(funcs, ysonYPathFuncs()...) + funcs = append(funcs, ysonAttributesFuncs()...) + funcs = append(funcs, ysonSerializeFuncs()...) + funcs = append(funcs, ysonOptionsFuncs()...) + + return funcs +} + +func ysonParseFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::Parse", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Yson"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::ParseJson", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Json"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::ParseJsonDecodeUtf8", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Json"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::Parse", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::ParseJson", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::ParseJsonDecodeUtf8", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } +} + +func ysonFromFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::From", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func ysonWithAttributesFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::WithAttributes", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } +} + +func ysonEqualsFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::Equals", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} + +func ysonGetHashFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::GetHash", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + } +} + +func ysonIsFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::IsEntity", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Yson::IsString", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Yson::IsDouble", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Yson::IsUint64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Yson::IsInt64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Yson::IsBool", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Yson::IsList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Yson::IsDict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} + +func ysonGetLengthFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::GetLength", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }, + } +} + +func ysonConvertToFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::ConvertTo", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::ConvertToBool", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::ConvertToInt64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Int64"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::ConvertToUint64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::ConvertToDouble", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::ConvertToString", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::ConvertToList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func ysonConvertToListFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::ConvertToBoolList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::ConvertToInt64List", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::ConvertToUint64List", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::ConvertToDoubleList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::ConvertToStringList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func ysonConvertToDictFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::ConvertToDict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::ConvertToBoolDict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::ConvertToInt64Dict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::ConvertToUint64Dict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::ConvertToDoubleDict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::ConvertToStringDict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func ysonContainsFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::Contains", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + ReturnTypeNullable: true, + }, + } +} + +func ysonLookupFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::Lookup", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::LookupBool", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::LookupInt64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Int64"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::LookupUint64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::LookupDouble", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::LookupString", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::LookupDict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::LookupList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } +} + +func ysonYPathFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::YPath", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::YPathBool", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::YPathInt64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Int64"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::YPathUint64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::YPathDouble", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::YPathString", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::YPathDict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::YPathList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } +} + +func ysonAttributesFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::Attributes", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func ysonSerializeFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::Serialize", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Yson"}, + }, + { + Name: "Yson::SerializeText", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Yson"}, + }, + { + Name: "Yson::SerializePretty", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Yson"}, + }, + { + Name: "Yson::SerializeJson", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Json"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::SerializeJson", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Json"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::SerializeJson", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Json"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::SerializeJson", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Json"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::SerializeJson", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Json"}, + ReturnTypeNullable: true, + }, + } +} + +func ysonOptionsFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::Options", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} diff --git a/internal/engine/ydb/lib/window.go b/internal/engine/ydb/lib/window.go new file mode 100644 index 0000000000..7c339217ad --- /dev/null +++ b/internal/engine/ydb/lib/window.go @@ -0,0 +1,163 @@ +package lib + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func WindowFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, rowNumberFuncs()...) + funcs = append(funcs, lagLeadFuncs()...) + funcs = append(funcs, firstLastValueFuncs()...) + funcs = append(funcs, nthValueFuncs()...) + funcs = append(funcs, rankFuncs()...) + funcs = append(funcs, ntileFuncs()...) + funcs = append(funcs, cumeDistFuncs()...) + funcs = append(funcs, sessionStartFuncs()...) + + return funcs +} + +func rowNumberFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "ROW_NUMBER", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + } +} + +func lagLeadFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "LAG", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "LAG", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "LEAD", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "LEAD", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } +} + +func firstLastValueFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "FIRST_VALUE", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "LAST_VALUE", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } +} + +func nthValueFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "NTH_VALUE", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } +} + +func rankFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "RANK", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "DENSE_RANK", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "PERCENT_RANK", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + } +} + +func ntileFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "NTILE", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + } +} + +func cumeDistFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "CUME_DIST", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + } +} + +func sessionStartFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "SESSION_START", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} diff --git a/internal/engine/ydb/stdlib.go b/internal/engine/ydb/stdlib.go index 21dc21242b..69ef6b223e 100644 --- a/internal/engine/ydb/stdlib.go +++ b/internal/engine/ydb/stdlib.go @@ -8,11 +8,15 @@ import ( func defaultSchema(name string) *catalog.Schema { s := &catalog.Schema{ Name: name, - Funcs: make([]*catalog.Function, 0, 128), + Funcs: []*catalog.Function{}, } s.Funcs = append(s.Funcs, lib.BasicFunctions()...) s.Funcs = append(s.Funcs, lib.AggregateFunctions()...) + s.Funcs = append(s.Funcs, lib.WindowFunctions()...) + s.Funcs = append(s.Funcs, lib.CppFunctions()...) + + // TODO: add container functions if return s } diff --git a/internal/sql/ast/recursive_func_call.go b/internal/sql/ast/recursive_func_call.go deleted file mode 100644 index 1c7c0a8125..0000000000 --- a/internal/sql/ast/recursive_func_call.go +++ /dev/null @@ -1,33 +0,0 @@ -package ast - -type RecursiveFuncCall struct { - Func Node - Funcname *List - Args *List - AggOrder *List - AggFilter Node - AggWithinGroup bool - AggStar bool - AggDistinct bool - FuncVariadic bool - Over *WindowDef - Location int -} - -func (n *RecursiveFuncCall) Pos() int { - return n.Location -} - -func (n *RecursiveFuncCall) Format(buf *TrackedBuffer) { - if n == nil { - return - } - buf.astFormat(n.Func) - buf.WriteString("(") - if n.AggStar { - buf.WriteString("*") - } else { - buf.astFormat(n.Args) - } - buf.WriteString(")") -} diff --git a/internal/sql/astutils/rewrite.go b/internal/sql/astutils/rewrite.go index bcc7c17e40..372d0ee7a2 100644 --- a/internal/sql/astutils/rewrite.go +++ b/internal/sql/astutils/rewrite.go @@ -1013,14 +1013,6 @@ func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast. a.apply(n, "Roles", nil, n.Roles) a.apply(n, "Newrole", nil, n.Newrole) - case *ast.RecursiveFuncCall: - a.apply(n, "Func", nil, n.Func) - a.apply(n, "Funcname", nil, n.Funcname) - a.apply(n, "Args", nil, n.Args) - a.apply(n, "AggOrder", nil, n.AggOrder) - a.apply(n, "AggFilter", nil, n.AggFilter) - a.apply(n, "Over", nil, n.Over) - case *ast.RefreshMatViewStmt: a.apply(n, "Relation", nil, n.Relation) diff --git a/internal/sql/astutils/walk.go b/internal/sql/astutils/walk.go index dfc313fda1..e7b78d126b 100644 --- a/internal/sql/astutils/walk.go +++ b/internal/sql/astutils/walk.go @@ -1734,26 +1734,6 @@ func Walk(f Visitor, node ast.Node) { Walk(f, n.Newrole) } - case *ast.RecursiveFuncCall: - if n.Func != nil { - Walk(f, n.Func) - } - if n.Funcname != nil { - Walk(f, n.Funcname) - } - if n.Args != nil { - Walk(f, n.Args) - } - if n.AggOrder != nil { - Walk(f, n.AggOrder) - } - if n.AggFilter != nil { - Walk(f, n.AggFilter) - } - if n.Over != nil { - Walk(f, n.Over) - } - case *ast.RefreshMatViewStmt: if n.Relation != nil { Walk(f, n.Relation)