Skip to content

Commit

Permalink
Can now call created functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Hydrocharged committed Feb 7, 2025
1 parent b8fd58f commit 14a2484
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241119094239-f4e529af734d
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
github.com/dolthub/go-icu-regex v0.0.0-20241215010122-db690dd53c90
github.com/dolthub/go-mysql-server v0.19.1-0.20250131110511-67aa2a430366
github.com/dolthub/go-mysql-server v0.19.1-0.20250207100547-b7600cbac71e
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216
github.com/dolthub/vitess v0.0.0-20250130172413-6338ebee2571
github.com/fatih/color v1.13.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U=
github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0=
github.com/dolthub/go-icu-regex v0.0.0-20241215010122-db690dd53c90 h1:Sni8jrP0sy/w9ZYXoff4g/ixe+7bFCZlfCqXKJSU+zM=
github.com/dolthub/go-icu-regex v0.0.0-20241215010122-db690dd53c90/go.mod h1:ylU4XjUpsMcvl/BKeRRMXSH7e7WBrPXdSLvnRJYrxEA=
github.com/dolthub/go-mysql-server v0.19.1-0.20250131110511-67aa2a430366 h1:pJ+upgX6hrhyqgpkmk9Ye9lIPSualMHZcUMs8kWknV4=
github.com/dolthub/go-mysql-server v0.19.1-0.20250131110511-67aa2a430366/go.mod h1:jYEJ8tNkA7K3k39X8iMqaX3MSMmViRgh222JSLHDgVc=
github.com/dolthub/go-mysql-server v0.19.1-0.20250207100547-b7600cbac71e h1:gnvZ08SWq+GceeP1+ewA2Iqpw66pbT3v5zW7/hl8ZnA=
github.com/dolthub/go-mysql-server v0.19.1-0.20250207100547-b7600cbac71e/go.mod h1:jYEJ8tNkA7K3k39X8iMqaX3MSMmViRgh222JSLHDgVc=
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI=
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q=
github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE=
Expand Down
2 changes: 2 additions & 0 deletions server/functions/framework/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/cockroachdb/errors"
"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/analyzer"
"github.com/dolthub/go-mysql-server/sql/expression/function"

pgtypes "github.com/dolthub/doltgresql/server/types"
Expand Down Expand Up @@ -76,6 +77,7 @@ func Initialize() {
initializedFunctions = true

pgtypes.LoadFunctionFromCatalog = getQuickFunctionForTypes
analyzer.ExternalFunctionProvider = &FunctionProvider{}
replaceGmsBuiltIns()
validateFunctions()
compileFunctions()
Expand Down
37 changes: 37 additions & 0 deletions server/functions/framework/provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2025 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package framework

import "github.com/dolthub/go-mysql-server/sql"

// FunctionProvider is the special sql.FunctionProvider for Doltgres that allows us to handle functions that were
// are created by users.
type FunctionProvider struct{}

var _ sql.FunctionProvider = (*FunctionProvider)(nil)

// Function implements the interface sql.FunctionProvider.
func (fp *FunctionProvider) Function(ctx *sql.Context, name string) (sql.Function, bool) {
// TODO: this should be configurable from within Dolt, rather than set on an external variable
// TODO: user functions should be accessible from the context, just like how sequences and types are handled
// For now, this just reads our global map (which also needs to be changed, since functions should not be global)
if f, ok := compiledCatalog[name]; ok {
return sql.FunctionN{
Name: name,
Fn: f,
}, true
}
return nil, false
}
1 change: 0 additions & 1 deletion testing/go/create_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func TestCreateFunction(t *testing.T) {
RunScripts(t, []ScriptTest{
{
Name: "Interpreter Assignment Example",
Skip: true, // TODO: need to use a Doltgres function provider, as the current one doesn't allow for adding functions
SetUpScript: []string{`CREATE FUNCTION interpreted_assignment(input TEXT) RETURNS TEXT AS $$
DECLARE
var1 TEXT;
Expand Down

0 comments on commit 14a2484

Please sign in to comment.