github.com/voedger/voedger@v0.0.0-20240520144910-273e84102129/pkg/processors/query/types.go (about)

     1  /*
     2   * Copyright (c) 2021-present unTill Pro, Ltd.
     3   *
     4   * * @author Michael Saigachenko
     5   */
     6  
     7  package queryprocessor
     8  
     9  import (
    10  	"context"
    11  
    12  	"github.com/voedger/voedger/pkg/appdef"
    13  	"github.com/voedger/voedger/pkg/istructs"
    14  	coreutils "github.com/voedger/voedger/pkg/utils"
    15  	ibus "github.com/voedger/voedger/staging/src/github.com/untillpro/airs-ibus"
    16  )
    17  
    18  // FilterFactory creates IFilter from data
    19  type FilterFactory func(data coreutils.MapObject) (IFilter, error)
    20  
    21  type IFilter interface {
    22  	IsMatch(fd FieldsKinds, outputRow IOutputRow) (bool, error)
    23  }
    24  
    25  // FieldFactory creates IField from data
    26  type FieldFactory func(data interface{}) (IField, error)
    27  
    28  // IField is the common interface for all field types
    29  type IField interface {
    30  	Field() string
    31  }
    32  
    33  // IResultField is the field from QueryHandler
    34  type IResultField interface {
    35  	IField
    36  }
    37  
    38  // IRefField is the field which references to classifier
    39  type IRefField interface {
    40  	IField
    41  	RefField() string
    42  	Key() string
    43  }
    44  
    45  // OrderByFactory creates IOrderBy from data
    46  type OrderByFactory func(data coreutils.MapObject) (IOrderBy, error)
    47  
    48  type IOrderBy interface {
    49  	Field() string
    50  	IsDesc() bool
    51  }
    52  
    53  type IQueryParams interface {
    54  	Elements() []IElement
    55  	Filters() []IFilter
    56  	OrderBy() []IOrderBy
    57  	StartFrom() int64
    58  	Count() int64
    59  }
    60  
    61  // ElementFactory creates IElement from data
    62  type ElementFactory func(data coreutils.MapObject) (IElement, error)
    63  
    64  type IElement interface {
    65  	Path() IPath
    66  	ResultFields() []IResultField
    67  	RefFields() []IRefField
    68  	NewOutputRow() IOutputRow
    69  }
    70  
    71  type IPath interface {
    72  	IsRoot() bool
    73  	Name() string
    74  	AsArray() []string
    75  }
    76  
    77  // IWorkpiece is a workpiece for row processor pipeline
    78  type IWorkpiece interface {
    79  	Object() istructs.IObject
    80  	OutputRow() IOutputRow
    81  	EnrichedRootFieldsKinds() FieldsKinds
    82  	PutEnrichedRootFieldKind(name string, kind appdef.DataKind)
    83  }
    84  
    85  // IOutputRow is filled by the row processor operators
    86  type IOutputRow interface {
    87  	Set(alias string, value interface{})
    88  	Value(alias string) interface{}
    89  	Values() []interface{}
    90  }
    91  
    92  type IQueryMessage interface {
    93  	AppQName() istructs.AppQName
    94  	WSID() istructs.WSID
    95  	Sender() ibus.ISender
    96  	Body() []byte
    97  	RequestCtx() context.Context
    98  	QName() appdef.QName
    99  	//TODO Denis provide partition
   100  	Partition() istructs.PartitionID
   101  	Host() string
   102  	Token() string
   103  }
   104  
   105  type ResultSenderClosableFactory func(ctx context.Context, sender ibus.ISender) IResultSenderClosable
   106  
   107  type IResultSenderClosable interface {
   108  	StartArraySection(sectionType string, path []string)
   109  	StartMapSection(sectionType string, path []string)
   110  	ObjectSection(sectionType string, path []string, element interface{}) (err error)
   111  	SendElement(name string, element interface{}) (err error)
   112  	Close(err error)
   113  }
   114  
   115  type IMetrics interface {
   116  	Increase(metricName string, valueDelta float64)
   117  }
   118  
   119  type FieldsKinds map[string]appdef.DataKind