github.com/siglens/siglens@v0.0.0-20240328180423-f7ce9ae441ed/pkg/segment/utils/segconsts.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 utils
    18  
    19  import (
    20  	"errors"
    21  	"fmt"
    22  	"regexp"
    23  	"strconv"
    24  	"strings"
    25  	"time"
    26  
    27  	"github.com/cespare/xxhash"
    28  )
    29  
    30  // ValType : One-byte that encodes data type of the value field
    31  // 0000 0001 ==> Bool
    32  // 0000 0010 ==> String
    33  // 0000 0011 ==> Uint8
    34  // 0000 0100 ==> Uint16
    35  // 0000 0101 ==> Uint32
    36  // 0000 0110 ==> Uint64
    37  // 0000 0111 ==> int8
    38  // 0000 1000 ==> int16
    39  // 0000 1001 ==> int32
    40  // 0000 1010 ==> int64
    41  // 0000 1011 ==> Float64
    42  
    43  // GLOBAL Defs
    44  // proportion of available to allocate for specific uses
    45  const MICRO_IDX_MEM_PERCENT = 35 // percent allocated for both rotated & unrotated metadata (cmi/searchmetadata)
    46  const SSM_MEM_PERCENT = 20
    47  const MICRO_IDX_CHECK_MEM_PERCENT = 5 // percent allocated for runtime checking & loading of cmis
    48  const BUFFER_MEM_PERCENT = 5
    49  const RAW_SEARCH_MEM_PERCENT = 15 // minimum percent allocated for segsearch
    50  const METRICS_MEMORY_MEM_PERCENT = 20
    51  
    52  // percent allocated for segmentsearchmeta (blocksummaries, blocklen/off)
    53  
    54  const BLOCK_MICRO_MULTINODE_MEM_PERCENT = 80
    55  const BLOCK_MICRO_CHECK_MULTINODE_MEM_PERCENT = 15
    56  const RAW_SEARCH_MULTINODE_MEM_PERCENT = 95
    57  const MULTINODE_SSM_MEM_PERCENT = 20
    58  
    59  // if you change this size, adjust the block bloom size
    60  const WIP_SIZE = 2_000_000
    61  const PQMR_SIZE uint = 4000 // init size of pqs bitset
    62  const WIP_NUM_RECS = 4000
    63  const BLOOM_SIZE_HISTORY = 5 // number of entries to analyze to get next block's bloom size
    64  const BLOCK_BLOOM_SIZE = 100 // the default should be on the smaller side. Let dynamic bloom sizing fix the optimal one
    65  const BLOCK_RI_MAP_SIZE = 100
    66  
    67  var MAX_BYTES_METRICS_BLOCK uint64 = 1e+8         // 100MB
    68  var METRICS_SEARCH_ALLOCATE_BLOCK uint64 = 1.5e+8 // 150MB
    69  var MAX_BYTES_METRICS_SEGMENT uint64 = 1e+10      // 10GB
    70  var MAX_ACTIVE_SERIES_PER_SEGMENT = 10_000_000
    71  
    72  const MAX_RAW_DATAPOINTS_IN_RESULT = 5_000_000
    73  
    74  // leave some room for column name/value meta
    75  // since we use 2 bytes for record len, columnname-len, we can accommodate 65535
    76  const MAX_RECORD_SIZE = 63_000
    77  const MAX_RECS_PER_WIP = 65_534
    78  const BLOOM_COLL_PROBABILITY = 0.001
    79  const RECORDLEN_BYTE_SIZE = 2
    80  
    81  const LEN_BLOCK_CMI_SIZE = 4
    82  const LEN_BLKNUM_CMI_SIZE = 2
    83  
    84  const LEN_PQMR_BLK_SIZE = 2
    85  
    86  const BLOCK_SUMMARY_SIZE = 50_000
    87  const BLOCK_SUMMARY_LEN_SIZE = 4
    88  const BLOCK_SUMMARY_TS_SIZE = 8
    89  const BLOCK_SUMMARY_REC_CNT_SIZE = 2
    90  
    91  const RI_SIZE = 2_000_000
    92  const RI_BLK_LEN_SIZE = 4
    93  
    94  const FILE_READ_BUFFER_SIZE = 100_000
    95  const DEFAULT_TIME_SLICE_SIZE = 10_000
    96  
    97  const COL_OFF_BYTE_SIZE = 2
    98  
    99  const NUMCOLS_OFF_START = RECORDLEN_BYTE_SIZE
   100  const NUMCOLS_OFF_END = NUMCOLS_OFF_START + 2
   101  
   102  const COL_BLK_OFF_START = NUMCOLS_OFF_END
   103  
   104  const BLOCK_BLOOM_SEPARATOR = ":"
   105  
   106  const MS_IN_MIN = 60_000     // 60 * 1000
   107  const MS_IN_HOUR = 3_600_000 // 60 * 60 * 1000
   108  const MS_IN_DAY = 86_400_000 // 24 * 60 * 60 * 1000
   109  
   110  var BYTE_SPACE = []byte(" ")
   111  var BYTE_SPACE_LEN = len(BYTE_SPACE)
   112  var BYTE_EMPTY_STRING = []byte("")
   113  
   114  var VALTYPE_ENC_BOOL = []byte{0x01}
   115  var VALTYPE_ENC_SMALL_STRING = []byte{0x02}
   116  var VALTYPE_ENC_UINT8 = []byte{0x03}
   117  var VALTYPE_ENC_UINT16 = []byte{0x04}
   118  var VALTYPE_ENC_UINT32 = []byte{0x05}
   119  var VALTYPE_ENC_UINT64 = []byte{0x06}
   120  var VALTYPE_ENC_INT8 = []byte{0x07}
   121  var VALTYPE_ENC_INT16 = []byte{0x08}
   122  var VALTYPE_ENC_INT32 = []byte{0x09}
   123  var VALTYPE_ENC_INT64 = []byte{0x10}
   124  var VALTYPE_ENC_FLOAT64 = []byte{0x11}
   125  var VALTYPE_ENC_LARGE_STRING = []byte{0x12}
   126  var VALTYPE_ENC_BACKFILL = []byte{0x13}
   127  var VALTYPE_DICT_ARRAY = []byte{0x14}
   128  var VALTYPE_RAW_JSON = []byte{0x15}
   129  
   130  var VERSION_TAGSTREE = []byte{0x01}
   131  var VERSION_TSOFILE = []byte{0x01}
   132  var VERSION_TSGFILE = []byte{0x01}
   133  var VERSION_MBLOCKSUMMARY = []byte{0x01}
   134  
   135  type SS_DTYPE uint8
   136  
   137  const (
   138  	SS_INVALID SS_DTYPE = iota
   139  	SS_DT_BOOL
   140  	SS_DT_SIGNED_NUM
   141  	SS_DT_UNSIGNED_NUM
   142  	SS_DT_FLOAT
   143  	SS_DT_STRING
   144  	SS_DT_STRING_SET
   145  	SS_DT_BACKFILL
   146  	SS_DT_SIGNED_32_NUM
   147  	SS_DT_USIGNED_32_NUM
   148  	SS_DT_SIGNED_16_NUM
   149  	SS_DT_USIGNED_16_NUM
   150  	SS_DT_SIGNED_8_NUM
   151  	SS_DT_USIGNED_8_NUM
   152  	SS_DT_ARRAY_DICT
   153  	SS_DT_RAW_JSON
   154  )
   155  
   156  const STALE_RECENTLY_ROTATED_ENTRY_MS = 60_000             // one minute
   157  const SEGMENT_ROTATE_DURATION_SECONDS = 15 * 60            // 15 mins
   158  var UPLOAD_INGESTNODE_DIR = time.Duration(1 * time.Minute) // one minute
   159  const SEGMENT_ROTATE_SLEEP_DURATION_SECONDS = 60           // 1 min
   160  
   161  var QUERY_EARLY_EXIT_LIMIT = uint64(10_000)
   162  var QUERY_MAX_BUCKETS = uint64(10_000)
   163  
   164  var ZSTD_COMLUNAR_BLOCK = []byte{0}
   165  var ZSTD_DICTIONARY_BLOCK = []byte{1}
   166  var TIMESTAMP_TOPDIFF_VARENC = []byte{2}
   167  var STAR_TREE_BLOCK = []byte{3}
   168  
   169  type SS_IntUintFloatTypes int
   170  
   171  const (
   172  	SS_UINT8 SS_IntUintFloatTypes = iota
   173  	SS_UINT16
   174  	SS_UINT32
   175  	SS_UINT64
   176  	SS_INT8
   177  	SS_INT16
   178  	SS_INT32
   179  	SS_INT64
   180  	SS_FLOAT64
   181  )
   182  
   183  type RangeNumType uint8
   184  
   185  // If you add new datatype under RangeNumType please add corresponding encoding VALTYPE_ENC_RNT_* in the following block
   186  const (
   187  	RNT_UNSIGNED_INT RangeNumType = iota
   188  	RNT_SIGNED_INT
   189  	RNT_FLOAT64
   190  )
   191  
   192  var VALTYPE_ENC_RNT_UNSIGNED_INT = []byte{0x00}
   193  var VALTYPE_ENC_RNT_SIGNED_INT = []byte{0x01}
   194  var VALTYPE_ENC_RNT_FLOAT64 = []byte{0x02}
   195  
   196  type FilterOperator int
   197  
   198  const (
   199  	Equals FilterOperator = iota
   200  	NotEquals
   201  	LessThan
   202  	LessThanOrEqualTo
   203  	GreaterThan
   204  	GreaterThanOrEqualTo
   205  	// Between - on the query parser to break down
   206  	// In - on the query parser to break down
   207  	IsNull
   208  	IsNotNull
   209  )
   210  
   211  func (e FilterOperator) ToString() string {
   212  	switch e {
   213  	case Equals:
   214  		return "eq"
   215  	case NotEquals:
   216  		return "neq"
   217  	case LessThan:
   218  		return "lt"
   219  	case GreaterThan:
   220  		return "gt"
   221  	case LessThanOrEqualTo:
   222  		return "lte"
   223  	case GreaterThanOrEqualTo:
   224  		return "gte"
   225  	default:
   226  		return fmt.Sprintf("%d", int(e))
   227  	}
   228  }
   229  
   230  var STAR_BYTE = []byte("*")
   231  
   232  // Maps a filter to its equivalent if left and right were swapped
   233  // If a range filter is given as left op right, what is the right op if it swaps to right op* left
   234  var ReflectFilterOperator = map[FilterOperator]FilterOperator{
   235  	Equals:               Equals,
   236  	NotEquals:            NotEquals,
   237  	LessThan:             GreaterThan,
   238  	LessThanOrEqualTo:    GreaterThanOrEqualTo,
   239  	GreaterThan:          LessThan,
   240  	GreaterThanOrEqualTo: LessThanOrEqualTo,
   241  	IsNull:               IsNull,
   242  	IsNotNull:            IsNotNull,
   243  }
   244  
   245  type ArithmeticOperator int
   246  
   247  const (
   248  	Add ArithmeticOperator = iota
   249  	Subtract
   250  	Divide
   251  	Multiply
   252  	Modulo
   253  	BitwiseAnd
   254  	BitwiseOr
   255  	BitwiseExclusiveOr
   256  )
   257  
   258  type LogicalAndArithmeticOperator int
   259  
   260  const (
   261  	LetAdd LogicalAndArithmeticOperator = iota
   262  	LetSubtract
   263  	LetDivide
   264  	LetMultiply
   265  	LetModulo
   266  	LetEquals
   267  	LetNotEquals
   268  	LetLessThan
   269  	LetLessThanOrEqualTo
   270  	LetGreaterThan
   271  	LetGreaterThanOrEqualTo
   272  )
   273  
   274  type AggregateFunctions int
   275  
   276  const (
   277  	Count AggregateFunctions = iota + 1
   278  	Avg
   279  	Min
   280  	Max
   281  	Range
   282  	Sum
   283  	Cardinality
   284  	Quantile
   285  	Values
   286  )
   287  
   288  type MathFunctions int
   289  
   290  const (
   291  	Round MathFunctions = iota + 1
   292  	Ceil
   293  	Abs
   294  	Sqrt
   295  	Exp
   296  )
   297  
   298  type RangeFunctions int
   299  
   300  const (
   301  	Derivative RangeFunctions = iota + 1
   302  	Rate
   303  )
   304  
   305  // For columns used by aggs with eval statements, we should keep their raw values because we need to evaluate them
   306  // For columns only used by aggs without eval statements, we should not keep their raw values because it is a waste of performance
   307  // If we only use two modes. Later occurring aggs will overwrite earlier occurring aggs' usage status. E.g. stats dc(eval(lower(state))), dc(state)
   308  type AggColUsageMode int
   309  
   310  const (
   311  	NoEvalUsage   AggColUsageMode = iota // NoEvalUsage indicates that the column will be used by an aggregator without an eval function
   312  	WithEvalUsage                        // WithEvalUsage indicates that the column will be used by an aggregator with an eval function
   313  	BothUsage                            // BothUsage indicates that the column will be used by both types of aggregators simultaneously
   314  )
   315  
   316  func (e AggregateFunctions) String() string {
   317  	switch e {
   318  	case Count:
   319  		return "count"
   320  	case Avg:
   321  		return "avg"
   322  	case Min:
   323  		return "min"
   324  	case Max:
   325  		return "max"
   326  	case Range:
   327  		return "range"
   328  	case Sum:
   329  		return "sum"
   330  	case Cardinality:
   331  		return "cardinality"
   332  	case Values:
   333  		return "values"
   334  	default:
   335  		return fmt.Sprintf("%d", int(e))
   336  	}
   337  }
   338  
   339  type TagOperator int
   340  
   341  const (
   342  	Equal TagOperator = iota
   343  	NotEqual
   344  	Regex
   345  	NegRegex
   346  )
   347  
   348  func (e TagOperator) String() string {
   349  	switch e {
   350  	case Equal:
   351  		return "eq"
   352  	case NotEqual:
   353  		return "neq"
   354  	default:
   355  		return fmt.Sprintf("%d", int(e))
   356  	}
   357  }
   358  
   359  type LogicalOperator int
   360  
   361  const (
   362  	Or LogicalOperator = iota
   363  	And
   364  	Exclusion
   365  )
   366  
   367  // every time you change this struct remember to adjust CreateDtypeEnclosure and ResetDtypeEnclosure
   368  type DtypeEnclosure struct {
   369  	Dtype          SS_DTYPE
   370  	BoolVal        uint8
   371  	UnsignedVal    uint64
   372  	SignedVal      int64
   373  	FloatVal       float64
   374  	StringVal      string
   375  	StringValBytes []byte         // byte slice representation of StringVal
   376  	rexpCompiled   *regexp.Regexp //  should be unexported to allow for gob encoding
   377  }
   378  
   379  func (dte *DtypeEnclosure) SetRegexp(exp *regexp.Regexp) {
   380  	dte.rexpCompiled = exp
   381  }
   382  
   383  func (dte *DtypeEnclosure) GetRegexp() *regexp.Regexp {
   384  	return dte.rexpCompiled
   385  }
   386  
   387  // used for numeric calcs and promotions
   388  type NumTypeEnclosure struct {
   389  	Ntype    SS_DTYPE `json:"ntype,omitempty"`
   390  	IntgrVal int64    `json:"intgrVal,omitempty"`
   391  	FloatVal float64  `json:"floatVal,omitempty"`
   392  }
   393  
   394  func (nte *NumTypeEnclosure) ToCValueEnclosure() (*CValueEnclosure, error) {
   395  	switch nte.Ntype {
   396  	case SS_DT_FLOAT:
   397  		return &CValueEnclosure{
   398  			Dtype: SS_DT_FLOAT,
   399  			CVal:  nte.FloatVal,
   400  		}, nil
   401  	case SS_DT_SIGNED_NUM, SS_DT_SIGNED_32_NUM, SS_DT_SIGNED_16_NUM, SS_DT_SIGNED_8_NUM:
   402  		return &CValueEnclosure{
   403  			Dtype: nte.Ntype,
   404  			CVal:  nte.IntgrVal,
   405  		}, nil
   406  	default:
   407  		return nil, fmt.Errorf("ToCValueEnclosure: unexpected Ntype: %v", nte.Ntype)
   408  	}
   409  }
   410  
   411  var CMI_BLOOM_INDEX = []byte{0x01}
   412  var CMI_RANGE_INDEX = []byte{0x02}
   413  var CMI_INVERTED_INDEX = []byte{0x03}
   414  
   415  func (dte *DtypeEnclosure) AddStringAsByteSlice() {
   416  	switch dte.Dtype {
   417  	case SS_DT_STRING:
   418  		dte.StringValBytes = []byte(dte.StringVal)
   419  	}
   420  }
   421  
   422  func (dte *DtypeEnclosure) IsNumeric() bool {
   423  	switch dte.Dtype {
   424  	case SS_DT_BOOL:
   425  		return false
   426  	case SS_DT_STRING:
   427  		return false
   428  	default:
   429  		return true
   430  	}
   431  }
   432  
   433  func (dte *DtypeEnclosure) IsString() bool {
   434  	switch dte.Dtype {
   435  	case SS_DT_STRING:
   436  		return true
   437  	default:
   438  		return false
   439  	}
   440  }
   441  
   442  func (dte *DtypeEnclosure) Reset() {
   443  	dte.Dtype = 0
   444  	dte.BoolVal = 0
   445  	dte.UnsignedVal = 0
   446  	dte.SignedVal = 0
   447  	dte.FloatVal = 0
   448  	dte.StringVal = ""
   449  	dte.rexpCompiled = nil
   450  }
   451  
   452  func (dte *DtypeEnclosure) IsFullWildcard() bool {
   453  	switch dte.Dtype {
   454  	case SS_DT_STRING:
   455  		if dte.StringVal == "*" {
   456  			return true
   457  		}
   458  		return dte.rexpCompiled != nil && dte.rexpCompiled.String() == ".*"
   459  	default:
   460  		return false
   461  	}
   462  }
   463  
   464  func (dte *DtypeEnclosure) IsRegex() bool {
   465  	switch dte.Dtype {
   466  	case SS_DT_STRING:
   467  		if strings.Contains(dte.StringVal, "*") {
   468  			return true
   469  		}
   470  		return dte.GetRegexp() != nil
   471  	default:
   472  		return false
   473  	}
   474  }
   475  
   476  func (dte *DtypeEnclosure) GetValue() (interface{}, error) {
   477  	switch dte.Dtype {
   478  	case SS_DT_STRING:
   479  		return dte.StringVal, nil
   480  	case SS_DT_BOOL:
   481  		return dte.BoolVal, nil
   482  	case SS_DT_UNSIGNED_NUM:
   483  		return dte.UnsignedVal, nil
   484  	case SS_DT_SIGNED_NUM:
   485  		return dte.SignedVal, nil
   486  	case SS_DT_FLOAT:
   487  		return dte.FloatVal, nil
   488  	case SS_DT_BACKFILL:
   489  		return nil, nil
   490  	default:
   491  		return nil, fmt.Errorf("GetValue: unsupported Dtype: %v", dte.Dtype)
   492  	}
   493  }
   494  
   495  type CValueEnclosure struct {
   496  	Dtype SS_DTYPE
   497  	CVal  interface{}
   498  }
   499  
   500  // resets the CValueEnclosure to the given value
   501  func (e *CValueEnclosure) ConvertValue(val interface{}) error {
   502  	switch val := val.(type) {
   503  	case string:
   504  		e.Dtype = SS_DT_STRING
   505  		e.CVal = val
   506  	case bool:
   507  		e.Dtype = SS_DT_BOOL
   508  		e.CVal = val
   509  	case uint64:
   510  		e.Dtype = SS_DT_UNSIGNED_NUM
   511  		e.CVal = val
   512  	case int64:
   513  		e.Dtype = SS_DT_SIGNED_NUM
   514  		e.CVal = val
   515  	case float64:
   516  		e.Dtype = SS_DT_FLOAT
   517  		e.CVal = val
   518  	case nil:
   519  		e.Dtype = SS_DT_BACKFILL
   520  		e.CVal = nil
   521  	default:
   522  		return fmt.Errorf("ConvertValue: unsupported type: %T", val)
   523  	}
   524  	return nil
   525  }
   526  
   527  func (e *CValueEnclosure) GetValue() (interface{}, error) {
   528  	switch e.Dtype {
   529  	case SS_DT_STRING_SET:
   530  		return e.CVal.(map[string]struct{}), nil
   531  	case SS_DT_STRING:
   532  		return e.CVal.(string), nil
   533  	case SS_DT_BOOL:
   534  		return e.CVal.(bool), nil
   535  	case SS_DT_UNSIGNED_NUM:
   536  		return e.CVal.(uint64), nil
   537  	case SS_DT_SIGNED_NUM:
   538  		return e.CVal.(int64), nil
   539  	case SS_DT_FLOAT:
   540  		return e.CVal.(float64), nil
   541  	case SS_DT_BACKFILL:
   542  		return nil, nil
   543  	default:
   544  		return nil, fmt.Errorf("GetValue: unsupported Dtype: %v", e.Dtype)
   545  	}
   546  }
   547  
   548  func (e *CValueEnclosure) GetString() (string, error) {
   549  	switch e.Dtype {
   550  	case SS_DT_STRING:
   551  		return e.CVal.(string), nil
   552  	case SS_DT_BOOL:
   553  		return strconv.FormatBool(e.CVal.(bool)), nil
   554  	case SS_DT_UNSIGNED_NUM:
   555  		return strconv.FormatUint(e.CVal.(uint64), 10), nil
   556  	case SS_DT_SIGNED_NUM:
   557  		return strconv.FormatInt(e.CVal.(int64), 10), nil
   558  	case SS_DT_FLOAT:
   559  		return fmt.Sprintf("%f", e.CVal.(float64)), nil
   560  	default:
   561  		return "", errors.New("CValueEnclosure GetString: unsupported Dtype")
   562  	}
   563  }
   564  
   565  func (e *CValueEnclosure) GetFloatValue() (float64, error) {
   566  	switch e.Dtype {
   567  	case SS_DT_STRING, SS_DT_BOOL:
   568  		return 0, errors.New("CValueEnclosure GetFloatValue: cannot convert to float")
   569  	case SS_DT_UNSIGNED_NUM:
   570  		return float64(e.CVal.(uint64)), nil
   571  	case SS_DT_SIGNED_NUM:
   572  		return float64(e.CVal.(int64)), nil
   573  	case SS_DT_FLOAT:
   574  		return e.CVal.(float64), nil
   575  	default:
   576  		return 0, errors.New("CValueEnclosure GetFloatValue: unsupported Dtype")
   577  	}
   578  }
   579  
   580  /*
   581  Returns a uint64 representation of the value
   582  
   583  if its a number, casts to uint64
   584  if its a string, xxhashed and returns it
   585  */
   586  func (e *CValueEnclosure) GetUIntValue() (uint64, error) {
   587  	switch e.Dtype {
   588  	case SS_DT_STRING:
   589  		return xxhash.Sum64String(e.CVal.(string)), nil
   590  	case SS_DT_BACKFILL:
   591  		return 0, nil
   592  	case SS_DT_BOOL:
   593  		if e.CVal.(bool) {
   594  			return 1, nil
   595  		} else {
   596  			return 0, nil
   597  		}
   598  	// Treat it as a Uint64; using it as a 4-byte object, not a number
   599  	case SS_DT_UNSIGNED_NUM:
   600  		return e.CVal.(uint64), nil
   601  	case SS_DT_FLOAT:
   602  		return uint64(e.CVal.(float64)), nil
   603  	case SS_DT_SIGNED_NUM:
   604  		return uint64(e.CVal.(int64)), nil
   605  	default:
   606  		return 0, errors.New("CValueEnclosure GetUIntValue: unsupported Dtype")
   607  	}
   608  }
   609  
   610  type CValueDictEnclosure struct {
   611  	Dtype       SS_DTYPE
   612  	CValString  string
   613  	CValBool    bool
   614  	CValUInt64  uint64
   615  	CValInt64   int64
   616  	CValFloat64 float64
   617  	CValUInt32  uint32
   618  	CValInt32   int32
   619  	CValUInt16  uint16
   620  	CValInt16   int16
   621  	CValUInt    uint8
   622  	CValInt     int8
   623  }
   624  
   625  func (e *CValueDictEnclosure) GetValue() (interface{}, error) {
   626  	switch e.Dtype {
   627  	case SS_DT_STRING:
   628  		return e.CValString, nil
   629  	case SS_DT_BOOL:
   630  		return e.CValBool, nil
   631  	case SS_DT_UNSIGNED_NUM:
   632  		return e.CValUInt64, nil
   633  	case SS_DT_SIGNED_NUM:
   634  		return e.CValInt64, nil
   635  	case SS_DT_FLOAT:
   636  		return e.CValFloat64, nil
   637  	case SS_DT_USIGNED_32_NUM:
   638  		return e.CValUInt32, nil
   639  	case SS_DT_SIGNED_32_NUM:
   640  		return e.CValInt32, nil
   641  	case SS_DT_USIGNED_16_NUM:
   642  		return e.CValUInt16, nil
   643  	case SS_DT_SIGNED_16_NUM:
   644  		return e.CValInt16, nil
   645  	case SS_DT_USIGNED_8_NUM:
   646  		return e.CValUInt, nil
   647  	case SS_DT_SIGNED_8_NUM:
   648  		return e.CValInt, nil
   649  	default:
   650  		return nil, errors.New("CValueDictEnclosure GetValue: unsupported Dtype")
   651  	}
   652  }
   653  
   654  // Information about the segment key for a record
   655  // Stores if the RRC came from a remote node
   656  type SegKeyInfo struct {
   657  	// Encoded segment key
   658  	SegKeyEnc uint16
   659  	// If the RRC came from a remote node
   660  	IsRemote bool
   661  	// if IsRemote, Record will be initialized to a string of the form <<node_id>>-<<segkey>>-<<block_num>>-<<record_num>>
   662  	RecordId string
   663  }
   664  
   665  type RecordResultContainer struct {
   666  	SegKeyInfo       SegKeyInfo // Information about the segment key for a record (remote or not)
   667  	BlockNum         uint16     // Block number of the record
   668  	RecordNum        uint16     // Record number of the record
   669  	SortColumnValue  float64    // Sort column value of the record
   670  	TimeStamp        uint64     // Timestamp of the record
   671  	VirtualTableName string     // Table name of the record
   672  }
   673  
   674  type BlkRecIdxContainer struct {
   675  	BlkRecIndexes    map[uint16]map[uint16]uint64
   676  	VirtualTableName string
   677  }
   678  
   679  func ConvertOperatorToString(op LogicalOperator) string {
   680  	switch op {
   681  	case And:
   682  		return "AND"
   683  	case Or:
   684  		return "OR"
   685  	case Exclusion:
   686  		return "EXCLUSION"
   687  	default:
   688  		return ""
   689  	}
   690  }
   691  
   692  type SIGNAL_TYPE uint8
   693  
   694  const (
   695  	SIGNAL_METRICS_OTSDB      = 1
   696  	SIGNAL_EVENTS             = 2
   697  	SIGNAL_JAEGER_TRACES      = 3
   698  	SIGNAL_METRICS_INFLUX     = 4
   699  	SIGNAL_METRICS_PROMETHEUS = 5
   700  )
   701  
   702  type RR_ENC_TYPE uint8
   703  
   704  const (
   705  	RR_ENC_UINT64 = 1
   706  	RR_ENC_BITSET = 2
   707  )