github.com/siglens/siglens@v0.0.0-20240328180423-f7ce9ae441ed/pkg/segment/structs/expressionstructs.go (about)

     1  /*
     2  Copyright 2023.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package structs
    18  
    19  import (
    20  	"github.com/siglens/siglens/pkg/config"
    21  	. "github.com/siglens/siglens/pkg/segment/utils"
    22  )
    23  
    24  // only one field will be non-nil
    25  // literal can either be a string or a json.Number
    26  type ExpressionInput struct {
    27  	ColumnValue *DtypeEnclosure // column value: "0", "abc", "abcd*", "0.213"
    28  	ColumnName  string          // column name for expression: "col1", "col2", ... "colN"
    29  }
    30  
    31  // expressions are used for SegReaders to parse and search segment files
    32  // If expressionOp == nil, only leftInput is not nil
    33  // else, only one of left/right ExpressionInput literal or columnName will be non empty
    34  //   - right expressionInput may not exist if op only needs one input (i.e. NOT_NULL)
    35  //
    36  // i.e field2 * 0.2, is Expression{leftInput=ExpressionInput{columnName=field2}, op=Multiply, rightInput=ExpressionInput{literal=0.2}}
    37  // for just literal  39, Expression{leftInput=ExpressionInput{literal=39}}
    38  type Expression struct {
    39  	LeftInput    *ExpressionInput   // left expression input for operator
    40  	ExpressionOp ArithmeticOperator // operator, used if complex expression that relates keys
    41  	RightInput   *ExpressionInput   // right expression input for operator
    42  }
    43  
    44  func (exp *Expression) IsTimeExpression() bool {
    45  	if exp.LeftInput != nil && len(exp.LeftInput.ColumnName) > 0 {
    46  		if exp.LeftInput.ColumnName == "*" {
    47  			return true
    48  		}
    49  		return exp.LeftInput.ColumnName == config.GetTimeStampKey()
    50  	}
    51  	if exp.RightInput != nil && len(exp.RightInput.ColumnName) > 0 {
    52  		if exp.RightInput.ColumnName == "*" {
    53  			return true
    54  		}
    55  		return exp.RightInput.ColumnName == config.GetTimeStampKey()
    56  	}
    57  	return false
    58  }