github.com/dolthub/go-mysql-server@v0.18.0/sql/plan/nothing.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 plan
    16  
    17  import "github.com/dolthub/go-mysql-server/sql"
    18  
    19  // NothingImpl is a node that will return no rows.
    20  var NothingImpl Nothing
    21  
    22  type Nothing struct{}
    23  
    24  var _ sql.Node = Nothing{}
    25  var _ sql.CollationCoercible = Nothing{}
    26  
    27  func (Nothing) String() string       { return "NOTHING" }
    28  func (Nothing) Resolved() bool       { return true }
    29  func (Nothing) IsReadOnly() bool     { return true }
    30  func (Nothing) Schema() sql.Schema   { return nil }
    31  func (Nothing) Children() []sql.Node { return nil }
    32  func (Nothing) RowIter(*sql.Context, sql.Row) (sql.RowIter, error) {
    33  	return sql.RowsToRowIter(), nil
    34  }
    35  
    36  // WithChildren implements the Node interface.
    37  func (n Nothing) WithChildren(children ...sql.Node) (sql.Node, error) {
    38  	if len(children) != 0 {
    39  		return nil, sql.ErrInvalidChildrenNumber.New(n, len(children), 0)
    40  	}
    41  
    42  	return NothingImpl, nil
    43  }
    44  
    45  // CheckPrivileges implements the interface sql.Node.
    46  func (Nothing) CheckPrivileges(ctx *sql.Context, opChecker sql.PrivilegedOperationChecker) bool {
    47  	return true
    48  }
    49  
    50  // CollationCoercibility implements the interface sql.CollationCoercible.
    51  func (Nothing) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
    52  	return sql.Collation_binary, 7
    53  }