Skip to content

Commit

Permalink
move type name to a method on localFunctionDialect interface
Browse files Browse the repository at this point in the history
  • Loading branch information
EpsilonPrime committed Jan 21, 2025
1 parent 3649e5c commit 074b73a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
16 changes: 2 additions & 14 deletions functions/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,6 @@ type mapAndSlice[V extensions.FunctionVariant] struct {
variantsSlice []V
}

func nameForInvocationType(invocationType interface{}) string {
switch invocationType.(type) {
case *LocalScalarFunctionVariant:
return "scalar function"
case *LocalAggregateFunctionVariant:
return "aggregate function"
case *LocalWindowFunctionVariant:
return "window function"
}
return "function"
}

// makeLocalFunctionVariantMapAndSlice creates a map of function names to their variants and a slice of all variants.
// The map is indexed by both the SubstraitFunctionName and the LocalFunctionName
// It returns
Expand All @@ -125,7 +113,7 @@ func makeLocalFunctionVariantMapAndSlice[T withID, V localFunctionVariant](
if _, nameAlreadyProcessed := variantsMap[LocalFunctionName(dfi.Name)]; nameAlreadyProcessed {
if _, ok := processedFunctions[dfi.ID]; !ok {
var invocationType V
return nil, fmt.Errorf("%w: no %s variant found for '%s'", substraitgo.ErrInvalidDialect, nameForInvocationType(invocationType), dfi.ID)
return nil, fmt.Errorf("%w: no %s function variant found for '%s'", substraitgo.ErrInvalidDialect, invocationType.InvocationTypeName(), dfi.ID)
}
continue
}
Expand All @@ -141,7 +129,7 @@ func makeLocalFunctionVariantMapAndSlice[T withID, V localFunctionVariant](
}
if _, ok := processedFunctions[dfi.ID]; !ok {
var invocationType V
return nil, fmt.Errorf("%w: no %s variant found for '%s'", substraitgo.ErrInvalidDialect, nameForInvocationType(invocationType), dfi.ID)
return nil, fmt.Errorf("%w: no %s function variant found for '%s'", substraitgo.ErrInvalidDialect, invocationType.InvocationTypeName(), dfi.ID)
}
if len(localVariantArray) > 0 {
addToSliceMap(variantsMap, SubstraitFunctionName(dfi.Name), localVariantArray)
Expand Down
13 changes: 13 additions & 0 deletions functions/registries.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ type localFunctionVariant interface {
LocalName() string
Notation() FunctionNotation
IsOptionSupported(name string, value string) bool
InvocationTypeName() string
}

type LocalFunctionVariant struct {
Expand Down Expand Up @@ -149,20 +150,32 @@ type LocalScalarFunctionVariant struct {

var _ extensions.FunctionVariant = &LocalScalarFunctionVariant{}

func (l *LocalScalarFunctionVariant) InvocationTypeName() string {
return "scalar"
}

type LocalAggregateFunctionVariant struct {
extensions.AggregateFunctionVariant
LocalFunctionVariant
}

var _ extensions.FunctionVariant = &LocalAggregateFunctionVariant{}

func (l *LocalAggregateFunctionVariant) InvocationTypeName() string {
return "aggregate"
}

type LocalWindowFunctionVariant struct {
extensions.WindowFunctionVariant
LocalFunctionVariant
}

var _ extensions.FunctionVariant = &LocalWindowFunctionVariant{}

func (l *LocalWindowFunctionVariant) InvocationTypeName() string {
return "window"
}

func newLocalScalarFunctionVariant(sf *extensions.ScalarFunctionVariant, dfi *dialectFunctionInfo) *LocalScalarFunctionVariant {
return &LocalScalarFunctionVariant{
ScalarFunctionVariant: *sf,
Expand Down

0 comments on commit 074b73a

Please sign in to comment.