// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you 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 compute

import (
	

	
	
	
)

// MatchSubstringOptions controls the substring matching functions such as
// starts_with, which match Pattern literally, not as a regular
// expression. With IgnoreCase, string and string_view input match Unicode
// simple case folds and require a valid UTF-8 pattern, while binary and
// binary_view input match ASCII case folds only. String case folding uses
// the tables of the Go toolchain's unicode package, so results can differ
// between Go versions.
type MatchSubstringOptions = kernels.MatchSubstringOptions

var startsWithDoc = FunctionDoc{
	Summary: "Check if strings start with a literal pattern",
	Description: "For each string in \"strings\", emit true iff it starts with a\n" +
		"given pattern. The pattern must be given in MatchSubstringOptions.\n" +
		"Null inputs emit null. Dictionary inputs are decoded to their value\n" +
		"type, and extension inputs use their storage type.",
	ArgNames:        []string{"strings"},
	OptionsType:     "MatchSubstringOptions",
	OptionsRequired: true,
}

type matchSubstringFunc struct {
	ScalarFunction
}

func ( *matchSubstringFunc) ( context.Context,  FunctionOptions,  ...Datum) (Datum, error) {
	if len() == 1 {
		,  := coalesceMultiBufferViewDatum(, [0])
		if  != nil {
			return nil, 
		}
		if  != nil {
			defer .Release()
			 = []Datum{}
		}
	}
	return execInternal(, , , -1, ...)
}

func ( *matchSubstringFunc) ( ...arrow.DataType) (exec.Kernel, error) {
	ensureDictionaryDecoded(...)
	ensureNoExtensionType(...)
	return .DispatchExact(...)
}

// RegisterScalarString registers the starts_with function.
func ( FunctionRegistry) {
	 := &matchSubstringFunc{*NewScalarFunction("starts_with", Unary(), startsWithDoc)}
	for ,  := range kernels.GetStartsWithKernels() {
		if  := .AddKernel();  != nil {
			panic()
		}
	}
	.AddFunction(, false)
}

// StartsWith returns, for each value in input, whether it starts with
// opts.Pattern. Null values produce null. Dictionary inputs are decoded
// to their value type, and extension inputs use their storage type.
func ( context.Context,  MatchSubstringOptions,  Datum) (Datum, error) {
	return CallFunction(, "starts_with", &, )
}