filter

package
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StringValueType = "string_value"
	DoubleValueType = "double_value"
	IntValueType    = "int_value"
	BoolValueType   = "bool_value"
	ArrayValueType  = "array_value"
)

Constants for property value types

Variables

View Source
var RestEntityPropertyMap = map[RestEntityType]map[string]bool{

	RestEntityRegisteredModel: {

		"id": true, "name": true, "externalId": true,
		"createTimeSinceEpoch": true, "lastUpdateTimeSinceEpoch": true,

		"state": true, "owner": true,
	},

	RestEntityModelVersion: {

		"id": true, "name": true, "externalId": true,
		"createTimeSinceEpoch": true, "lastUpdateTimeSinceEpoch": true,

		"registeredModelId": true, "state": true, "author": true,
	},

	RestEntityInferenceService: {

		"id": true, "name": true, "externalId": true,
		"createTimeSinceEpoch": true, "lastUpdateTimeSinceEpoch": true,

		"registeredModelId": true, "modelVersionId": true, "servingEnvironmentId": true,
		"runtime": true, "desiredState": true,
	},

	RestEntityServingEnvironment: {

		"id": true, "name": true, "externalId": true,
		"createTimeSinceEpoch": true, "lastUpdateTimeSinceEpoch": true,
	},

	RestEntityExperiment: {

		"id": true, "name": true, "externalId": true,
		"createTimeSinceEpoch": true, "lastUpdateTimeSinceEpoch": true,

		"state": true, "owner": true,
	},

	RestEntityExperimentRun: {

		"id": true, "name": true, "externalId": true,
		"createTimeSinceEpoch": true, "lastUpdateTimeSinceEpoch": true,

		"experimentId": true, "startTimeSinceEpoch": true, "endTimeSinceEpoch": true,
		"status": true, "state": true, "owner": true,
	},

	RestEntityModelArtifact: {

		"id": true, "name": true, "externalId": true,
		"createTimeSinceEpoch": true, "lastUpdateTimeSinceEpoch": true,
		"uri": true, "state": true,

		"modelFormatName": true, "modelFormatVersion": true,
		"storageKey": true, "storagePath": true, "serviceAccountName": true,
		"modelSourceKind": true, "modelSourceClass": true, "modelSourceGroup": true,
		"modelSourceId": true, "modelSourceName": true,

		"experimentId": true, "experimentRunId": true,
	},

	RestEntityDocArtifact: {

		"id": true, "name": true, "externalId": true,
		"createTimeSinceEpoch": true, "lastUpdateTimeSinceEpoch": true,
		"uri": true, "state": true,

		"experimentId": true, "experimentRunId": true,
	},

	RestEntityDataSet: {

		"id": true, "name": true, "externalId": true,
		"createTimeSinceEpoch": true, "lastUpdateTimeSinceEpoch": true,
		"uri": true, "state": true,

		"digest": true, "sourceType": true, "source": true, "schema": true, "profile": true,

		"experimentId": true, "experimentRunId": true,
	},

	RestEntityMetric: {

		"id": true, "name": true, "externalId": true,
		"createTimeSinceEpoch": true, "lastUpdateTimeSinceEpoch": true,
		"uri": true, "state": true,

		"value": true, "timestamp": true, "step": true,

		"experimentId": true, "experimentRunId": true,
	},

	RestEntityParameter: {

		"id": true, "name": true, "externalId": true,
		"createTimeSinceEpoch": true, "lastUpdateTimeSinceEpoch": true,
		"uri": true, "state": true,

		"value": true, "parameterType": true,

		"experimentId": true, "experimentRunId": true,
	},

	RestEntityServeModel: {

		"id": true, "name": true, "externalId": true,
		"createTimeSinceEpoch": true, "lastUpdateTimeSinceEpoch": true,
		"lastKnownState": true,

		"modelVersionId": true, "inferenceServiceId": true,
		"registeredModelId": true, "servingEnvironmentId": true,
	},
}

RestEntityPropertyMap maps REST entity types to their allowed properties

Functions

This section is empty.

Types

type AndExpression

type AndExpression struct {
	Left  *Term   `@@`
	Right []*Term `("AND" @@)*`
}

type Comparison

type Comparison struct {
	Left     *PropertyRef `@@`
	Operator string       `@("=" | "!=" | "<>" | ">=" | "<=" | ">" | "<" | "LIKE" | "ILIKE" | "IN")`
	Right    *Value       `@@`
}

type EntityMappingFunctions added in v0.3.2

type EntityMappingFunctions interface {
	// GetMLMDEntityType maps a REST entity type to its underlying MLMD entity type
	GetMLMDEntityType(restEntityType RestEntityType) EntityType

	// GetPropertyDefinitionForRestEntity returns property definition for a REST entity type
	GetPropertyDefinitionForRestEntity(restEntityType RestEntityType, propertyName string) PropertyDefinition

	// IsChildEntity returns true if the REST entity type uses prefixed names (parentId:name)
	IsChildEntity(entityType RestEntityType) bool
}

EntityMappingFunctions defines the interface for entity type mapping functions This allows different packages (like catalog) to provide their own entity mappings

type EntityPropertyMap

type EntityPropertyMap map[string]PropertyDefinition

EntityPropertyMap maps property names to their definitions for each entity type

type EntityType

type EntityType string

EntityType represents the type of entity for proper query building

const (
	EntityTypeContext   EntityType = "context"
	EntityTypeArtifact  EntityType = "artifact"
	EntityTypeExecution EntityType = "execution"
)

func GetMLMDEntityType

func GetMLMDEntityType(restEntityType RestEntityType) EntityType

GetMLMDEntityType maps REST entity types to their underlying MLMD entity type

type Expression

type Expression struct {
	Or *OrExpression `@@`
}

type FilterExpression

type FilterExpression struct {
	Left     *FilterExpression
	Right    *FilterExpression
	Operator string
	Property string
	Value    interface{}
	IsLeaf   bool
}

FilterExpression represents a parsed filter expression (keeping for compatibility)

func Parse

func Parse(input string) (*FilterExpression, error)

Parse parses a filter query string and returns the root expression This function is thread-safe and reuses a singleton parser instance

type OrExpression

type OrExpression struct {
	Left  *AndExpression   `@@`
	Right []*AndExpression `("OR" @@)*`
}

type PropertyDefinition

type PropertyDefinition struct {
	Location  PropertyLocation
	ValueType string // IntValueType, StringValueType, DoubleValueType, BoolValueType
	Column    string // Database column name (for entity table) or property name (for property table)

	// Fields for related entity properties
	RelatedEntityType RelatedEntityType // Type of related entity (artifact, context, execution)
	RelatedProperty   string            // Property name in the related entity
	JoinTable         string            // Table to join through (e.g., "Attribution", "ParentContext")
}

PropertyDefinition defines how a property should be handled

func GetPropertyDefinition

func GetPropertyDefinition(entityType EntityType, propertyName string) PropertyDefinition

GetPropertyDefinition returns the property definition for a given entity type and property name

func GetPropertyDefinitionForRestEntity

func GetPropertyDefinitionForRestEntity(restEntityType RestEntityType, propertyName string) PropertyDefinition

GetPropertyDefinitionForRestEntity returns property definition for a REST entity type This function determines the correct data type and storage location for properties

type PropertyLocation

type PropertyLocation int

PropertyLocation indicates where a property is stored

const (
	EntityTable   PropertyLocation = iota // Property is a column in the main entity table
	PropertyTable                         // Property is stored in the entity's property table
	Custom                                // Property is a custom property in the property table
	RelatedEntity                         // Property is in a related entity (requires JOIN)
)

type PropertyRef

type PropertyRef struct {
	EscapedName string   `@EscapedIdent`
	Name        string   `| @Ident`
	Path        []string `("." @Ident)*`
	Type        string   `("." @("string_value" | "double_value" | "int_value" | "bool_value"))?`
}

type PropertyReference

type PropertyReference struct {
	Name        string
	IsCustom    bool
	ValueType   string             // StringValueType, DoubleValueType, IntValueType, BoolValueType, ArrayValueType
	IsEscaped   bool               // whether the property name was escaped with backticks
	PropertyDef PropertyDefinition // Full property definition for advanced handling
}

PropertyReference represents a property reference with type information

type QueryBuilder

type QueryBuilder struct {
	// contains filtered or unexported fields
}

QueryBuilder builds GORM queries from filter expressions It handles special cases like prefixed names for child entities (e.g., ModelVersion, ExperimentRun) where names are stored as "parentId:actualName" in the database

func NewQueryBuilderForRestEntity

func NewQueryBuilderForRestEntity(restEntityType RestEntityType, mappingFuncs EntityMappingFunctions) *QueryBuilder

NewQueryBuilderForRestEntity creates a new query builder for the specified REST entity type If mappingFuncs is nil, it falls back to the global functions

func (*QueryBuilder) BuildQuery

func (qb *QueryBuilder) BuildQuery(db *gorm.DB, expr *FilterExpression) *gorm.DB

BuildQuery builds a GORM query from a filter expression

func (*QueryBuilder) ConvertStateValue added in v0.3.1

func (qb *QueryBuilder) ConvertStateValue(propertyName string, value any) any

ConvertStateValue converts string state values to integers based on entity type

type RelatedEntityType added in v0.3.3

type RelatedEntityType string

RelatedEntityType indicates the type of related entity

const (
	RelatedEntityArtifact  RelatedEntityType = "artifact"
	RelatedEntityContext   RelatedEntityType = "context"
	RelatedEntityExecution RelatedEntityType = "execution"
)

type RestEntityType

type RestEntityType string

RestEntityType represents the specific REST API entity type

const (
	// Context-based REST entities
	RestEntityRegisteredModel    RestEntityType = "RegisteredModel"
	RestEntityModelVersion       RestEntityType = "ModelVersion"
	RestEntityInferenceService   RestEntityType = "InferenceService"
	RestEntityServingEnvironment RestEntityType = "ServingEnvironment"
	RestEntityExperiment         RestEntityType = "Experiment"
	RestEntityExperimentRun      RestEntityType = "ExperimentRun"

	// Artifact-based REST entities
	RestEntityModelArtifact RestEntityType = "ModelArtifact"
	RestEntityDocArtifact   RestEntityType = "DocArtifact"
	RestEntityDataSet       RestEntityType = "DataSet"
	RestEntityMetric        RestEntityType = "Metric"
	RestEntityParameter     RestEntityType = "Parameter"

	// Execution-based REST entities
	RestEntityServeModel RestEntityType = "ServeModel"
)

type SingleValue

type SingleValue struct {
	String  *string  `@String`
	Integer *int64   `| @Int`
	Float   *float64 `| @Float`
	Boolean *string  `| @("true" | "false" | "TRUE" | "FALSE")`
}

type Term

type Term struct {
	Group      *Expression `"(" @@ ")"`
	Comparison *Comparison `| @@`
}

type Value

type Value struct {
	String    *string    `@String`
	Integer   *int64     `| @Int`
	Float     *float64   `| @Float`
	Boolean   *string    `| @("true" | "false" | "TRUE" | "FALSE")`
	ValueList *ValueList `| @@`
}

type ValueList

type ValueList struct {
	Values []*SingleValue `"(" (@@  ("," @@)*)? ")"`
}

type WhereClause

type WhereClause struct {
	Expression *Expression `@@`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL