github.com/dolthub/go-mysql-server@v0.18.0/sql/expression/default.go (about)

     1  // Copyright 2020-2021 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 (
    18  	"github.com/dolthub/go-mysql-server/sql"
    19  )
    20  
    21  // DefaultColumn is a default expression of a column that is not yet resolved.
    22  type DefaultColumn struct {
    23  	name string
    24  }
    25  
    26  var _ sql.Expression = (*DefaultColumn)(nil)
    27  var _ sql.CollationCoercible = (*DefaultColumn)(nil)
    28  
    29  // NewDefaultColumn creates a new NewDefaultColumn expression.
    30  func NewDefaultColumn(name string) *DefaultColumn {
    31  	return &DefaultColumn{name: name}
    32  }
    33  
    34  // Children implements the sql.Expression interface.
    35  // The function returns always nil
    36  func (*DefaultColumn) Children() []sql.Expression {
    37  	return nil
    38  }
    39  
    40  // Resolved implements the sql.Expression interface.
    41  // The function returns always false
    42  func (*DefaultColumn) Resolved() bool {
    43  	return false
    44  }
    45  
    46  // IsNullable implements the sql.Expression interface.
    47  // The function always panics!
    48  func (*DefaultColumn) IsNullable() bool {
    49  	panic("default column is a placeholder node, but IsNullable was called")
    50  }
    51  
    52  // Type implements the sql.Expression interface.
    53  // The function always panics!
    54  func (*DefaultColumn) Type() sql.Type {
    55  	panic("default column is a placeholder node, but Type was called")
    56  }
    57  
    58  // CollationCoercibility implements the interface sql.CollationCoercible.
    59  func (*DefaultColumn) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
    60  	return sql.Collation_binary, 7
    61  }
    62  
    63  // Name implements the sql.Nameable interface.
    64  func (c *DefaultColumn) Name() string { return c.name }
    65  
    66  // String implements the Stringer
    67  // The function returns column's name (can be an empty string)
    68  func (c *DefaultColumn) String() string {
    69  	return c.name
    70  }
    71  
    72  // Eval implements the sql.Expression interface.
    73  // The function always panics!
    74  func (*DefaultColumn) Eval(ctx *sql.Context, r sql.Row) (interface{}, error) {
    75  	panic("default column is a placeholder node, but Eval was called")
    76  }
    77  
    78  // WithChildren implements the Expression interface.
    79  func (c *DefaultColumn) WithChildren(children ...sql.Expression) (sql.Expression, error) {
    80  	if len(children) != 0 {
    81  		return nil, sql.ErrInvalidChildrenNumber.New(c, len(children), 0)
    82  	}
    83  	return c, nil
    84  }