|
| 1 | +// Copyright 2025 Dolthub, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package expression |
| 16 | + |
| 17 | +import "github.com/dolthub/go-mysql-server/sql" |
| 18 | + |
| 19 | +// ExpressionFactory allows integrators to provide custom implementations of |
| 20 | +// expressions, such as IS NULL and IS NOT NULL. |
| 21 | +type ExpressionFactory interface { |
| 22 | + // NewIsNull returns a sql.Expression implementation that handles |
| 23 | + // the IS NULL expression. |
| 24 | + NewIsNull(e sql.Expression) sql.Expression |
| 25 | + // NewIsNotNull returns a sql.Expression implementation that handles |
| 26 | + // the IS NOT NULL expression. |
| 27 | + NewIsNotNull(e sql.Expression) sql.Expression |
| 28 | +} |
| 29 | + |
| 30 | +// DefaultExpressionFactory is the ExpressionFactory used when the analyzer |
| 31 | +// needs to create new expressions during analysis, such as IS NULL or |
| 32 | +// IS NOT NULL. Integrators can swap in their own implementation if they need |
| 33 | +// to customize the existing logic for these expressions. |
| 34 | +var DefaultExpressionFactory ExpressionFactory = MySqlExpressionFactory{} |
| 35 | + |
| 36 | +// MySqlExpressionFactory is the ExpressionFactory that creates expressions |
| 37 | +// that follow MySQL's logic. |
| 38 | +type MySqlExpressionFactory struct{} |
| 39 | + |
| 40 | +var _ ExpressionFactory = (*MySqlExpressionFactory)(nil) |
| 41 | + |
| 42 | +// NewIsNull implements the ExpressionFactory interface. |
| 43 | +func (m MySqlExpressionFactory) NewIsNull(e sql.Expression) sql.Expression { |
| 44 | + return NewIsNull(e) |
| 45 | +} |
| 46 | + |
| 47 | +// NewIsNotNull implements the ExpressionFactory interface. |
| 48 | +func (m MySqlExpressionFactory) NewIsNotNull(e sql.Expression) sql.Expression { |
| 49 | + return NewNot(NewIsNull(e)) |
| 50 | +} |
0 commit comments