import type * as Malloy from '@malloydata/malloy-interfaces'; /** * Field computations are compiled into an expression tree of "Expr" * type nodes. Each node is one of these three interfaces. The * final type "Expr" is a union type of all known nodes, so * that you can use "if (expr.node === 'nodeType')" instead of * having to write discriminator functions for every node type. */ export interface ExprLeaf { node: string; typeDef?: AtomicTypeDef; sql?: string; } export interface ExprE extends ExprLeaf { e: Expr; } export interface ExprOptionalE extends ExprLeaf { e?: Expr; } export interface ExprWithKids extends ExprLeaf { kids: Record; } export type AnyExpr = ExprE | ExprOptionalE | ExprWithKids | ExprLeaf; export declare function exprHasKids(e: AnyExpr): e is ExprWithKids; export declare function exprHasE(e: AnyExpr): e is ExprE; export declare function exprIsLeaf(e: AnyExpr): boolean; export type Expr = BinaryExpr | UnaryExpr | FunctionCallNode | OutputFieldNode | FilterCondition | FilteredExpr | AggregateExpr | EmptyExpr | UngroupNode | FunctionParameterNode | SpreadExpr | AggregateOrderByNode | AggregateLimitNode | FieldnameNode | SourceReferenceNode | ParameterNode | NowNode | MeasureTimeExpr | TimeExtractExpr | TimeDeltaExpr | TimeTruncExpr | TimeLiteralNode | TypecastExpr | RegexMatchExpr | RegexLiteralNode | FilterMatchExpr | FilterLiteralExpr | StringLiteralNode | NumberLiteralNode | BooleanLiteralNode | RecordLiteralNode | ArrayLiteralNode | FunctionOrderBy | GenericSQLExpr | NullNode | CaseExpr | InCompareExpr | CompositeFieldExpr | ErrorNode; export type BinaryOperator = '+' | '-' | '*' | '%' | '/' | 'and' | 'or' | '=' | '!=' | '>' | '<' | '>=' | '<=' | 'coalesce' | 'like' | '!like'; export interface BinaryExpr extends ExprWithKids { node: BinaryOperator; kids: { left: Expr; right: Expr; }; } export type UnaryOperator = '()' | 'not' | 'unary-' | 'is-null' | 'is-not-null'; export interface UnaryExpr extends ExprE { node: UnaryOperator; e: Expr; } export interface FunctionCallNode extends ExprWithKids { node: 'function_call'; name: string; overload: FunctionOverloadDef; expressionType: ExpressionType; kids: { args: Expr[]; orderBy?: FunctionOrderBy[]; }; limit?: number; partitionBy?: string[]; structPath?: string[]; } export interface OutputFieldNode extends ExprLeaf { node: 'outputField'; name: string; } export interface FilterCondition extends ExprE { node: 'filterCondition'; code: string; expressionType: ExpressionType; fieldUsage?: FieldUsage[]; filterView?: string; stableFilter?: Malloy.Filter; isSourceFilter?: boolean; } export interface FilteredExpr extends ExprWithKids { node: 'filteredExpr'; kids: { e: Expr; filterList: FilterCondition[]; }; } export type AggregateFunctionType = 'sum' | 'avg' | 'count' | 'distinct' | 'max' | 'min'; export interface AggregateExpr extends ExprE { node: 'aggregate'; function: AggregateFunctionType; structPath?: string[]; at?: DocumentLocation; } export declare function isAsymmetricExpr(f: Expr): f is AggregateExpr; export interface EmptyExpr extends ExprLeaf { node: ''; } export interface UngroupNode extends ExprE { node: 'all' | 'exclude'; fields?: string[]; } export interface FunctionParameterNode extends ExprLeaf { node: 'function_parameter'; name: string; } export interface AggregateOrderByNode extends ExprLeaf { node: 'aggregate_order_by'; prefix?: string; suffix?: string; } export interface AggregateLimitNode extends ExprLeaf { node: 'aggregate_limit'; } export interface SpreadExpr extends ExprE { node: 'spread'; prefix: string | undefined; suffix: string | undefined; } export interface FieldnameNode extends ExprLeaf { node: 'field'; path: string[]; at?: DocumentLocation; } export interface SourceReferenceNode extends ExprLeaf { node: 'source-reference'; path?: string[]; } export interface ParameterNode extends ExprLeaf { node: 'parameter'; path: string[]; } export interface NowNode extends ExprLeaf { node: 'now'; typeDef: { type: 'timestamp'; }; } interface HasTimeValue { typeDef: TemporalTypeDef; } export type TimeExpr = Expr & HasTimeValue; export declare function mkTemporal(e: Expr, timeType: TemporalTypeDef | TemporalFieldType): TimeExpr; export interface MeasureTimeExpr extends ExprWithKids { node: 'timeDiff'; units: TimestampUnit; kids: { left: TimeExpr; right: TimeExpr; }; } export interface TimeDeltaExpr extends ExprWithKids { node: 'delta'; kids: { base: TimeExpr; delta: Expr; }; op: '+' | '-'; units: TimestampUnit; } export interface TimeTruncExpr extends ExprE { node: 'trunc'; e: TimeExpr; units: TimestampUnit; } export interface TimeExtractExpr extends ExprE { node: 'extract'; e: TimeExpr; units: ExtractUnit; } export interface MalloyTypecastExpr extends ExprE { node: 'cast'; safe: boolean; e: Expr; dstType: BasicAtomicTypeDef; srcType?: BasicAtomicTypeDef; } interface RawTypeCastExpr extends ExprE { node: 'cast'; safe: boolean; e: Expr; dstSQLType: string; srcType?: BasicAtomicTypeDef; } export type TypecastExpr = MalloyTypecastExpr | RawTypeCastExpr; export declare function isRawCast(te: TypecastExpr): te is RawTypeCastExpr; export interface RegexMatchExpr extends ExprWithKids { node: 'regexpMatch'; kids: { expr: Expr; regex: Expr; }; } export type FilterExprType = 'string' | 'number' | 'boolean' | 'date' | 'timestamp'; export declare function isFilterExprType(s: string): s is FilterExprType; export interface FilterMatchExpr extends ExprWithKids { node: 'filterMatch'; dataType: FilterExprType; notMatch?: true; kids: { filterExpr: Expr; expr: Expr; }; } export interface FilterLiteralExpr extends ExprLeaf { node: 'filterLiteral'; filterSrc: string; } export interface TimeLiteralNode extends ExprLeaf { node: 'timeLiteral'; literal: string; typeDef: TemporalTypeDef; timezone?: string; } export interface StringLiteralNode extends ExprLeaf { node: 'stringLiteral'; literal: string; } export interface RegexLiteralNode extends ExprLeaf { node: 'regexpLiteral'; literal: string; } export interface NumberLiteralNode extends ExprLeaf { node: 'numberLiteral'; literal: string; } export interface BooleanLiteralNode extends ExprLeaf { node: 'true' | 'false'; } export interface RecordLiteralNode extends ExprWithKids { node: 'recordLiteral'; kids: Record; typeDef: RecordTypeDef; } export interface ArrayLiteralNode extends ExprWithKids { node: 'arrayLiteral'; kids: { values: Expr[]; }; typeDef: ArrayTypeDef; } export interface ErrorNode extends ExprLeaf { node: 'error'; message?: string; } export interface GenericSQLExpr extends ExprWithKids { node: 'genericSQLExpr'; kids: { args: Expr[]; }; src: string[]; } export interface NullNode extends ExprLeaf { node: 'null'; } export interface CaseExpr extends ExprWithKids { node: 'case'; kids: { caseValue?: Expr; caseWhen: Expr[]; caseThen: Expr[]; caseElse?: Expr; }; } export interface CompositeFieldExpr extends ExprLeaf { node: 'compositeField'; } export interface InCompareExpr extends ExprWithKids { node: 'in'; not: boolean; kids: { e: Expr; oneOf: Expr[]; }; } export type ExpressionType = 'scalar' | 'aggregate' | 'scalar_analytic' | 'aggregate_analytic' | 'ungrouped_aggregate'; export interface Expression { e?: Expr; fieldUsage?: FieldUsage[]; expressionType?: ExpressionType; code?: string; drillExpression?: Malloy.Expression; } type ConstantExpr = Expr; interface ParameterInfo { name: string; value: ConstantExpr | null; } interface FilterExpressionParamTypeDef { type: 'filter expression'; filterType: FilterExprType; } export type ParameterType = 'string' | 'number' | 'boolean' | 'date' | 'timestamp' | 'filter expression' | 'error'; export declare function isParameterType(t: string): t is ParameterType; export type ParameterTypeDef = StringTypeDef | NumberTypeDef | BooleanTypeDef | TemporalTypeDef | FilterExpressionParamTypeDef | ErrorTypeDef; export type Parameter = ParameterTypeDef & ParameterInfo; export type Argument = Parameter; export declare function paramHasValue(p: Parameter): boolean; export interface DocumentRange { start: DocumentPosition; end: DocumentPosition; } export interface DocumentPosition { line: number; character: number; } export interface ImportLocation { importURL: string; location: DocumentLocation; } export interface DocumentLocation { url: string; range: DocumentRange; } interface DocumentReferenceBase { text: string; location: DocumentLocation; definition: HasLocation; } export interface DocumentExploreReference extends DocumentReferenceBase { type: 'exploreReference'; definition: StructDef; } export interface DocumentJoinReference extends DocumentReferenceBase { type: 'joinReference'; definition: FieldDef; } export interface DocumentSQLBlockReference extends DocumentReferenceBase { type: 'sqlBlockReference'; definition: SQLSourceDef; } export interface DocumentQueryReference extends DocumentReferenceBase { type: 'queryReference'; definition: Query; } export interface DocumentFieldReference extends DocumentReferenceBase { type: 'fieldReference'; definition: FieldDef; } export type DocumentReference = DocumentExploreReference | DocumentQueryReference | DocumentSQLBlockReference | DocumentFieldReference | DocumentJoinReference; /** put location into the parse tree. */ export interface HasLocation { location?: DocumentLocation; } /** All names have their source names and how they will appear in the symbol table that owns them */ export interface AliasedName { name: string; as?: string; } /** all named objects have a type an a name (optionally aliased) */ export interface NamedObject extends AliasedName, HasLocation { type: string; } export interface ResultMetadataDef { sourceField: string; sourceExpression?: string; sourceClasses: string[]; filterList?: FilterCondition[]; fieldKind: 'measure' | 'dimension' | 'struct'; referenceId?: string; drillExpression?: Malloy.Expression | undefined; drillable?: boolean; } export interface Ordered { orderBy?: OrderBy[]; defaultOrderBy?: boolean; } export interface ResultStructMetadataDef extends ResultMetadataDef, Ordered { limit?: number; } export interface ResultMetadata { resultMetadata?: ResultMetadataDef; } export interface ResultStructMetadata { resultMetadata?: ResultStructMetadataDef; } export declare function expressionIsScalar(e: ExpressionType | undefined): boolean; export declare function expressionIsAggregate(e: ExpressionType | undefined): boolean; export declare function expressionIsUngroupedAggregate(e: ExpressionType | undefined): boolean; export declare function expressionInvolvesAggregate(e: ExpressionType | undefined): boolean; export declare function expressionIsCalculation(e: ExpressionType | undefined): boolean; export declare function expressionIsAnalytic(e: ExpressionType | undefined): boolean; export declare function isExpressionTypeLEQ(e1: ExpressionType, e2: ExpressionType): boolean; export declare function maxExpressionType(e1: ExpressionType, e2: ExpressionType): ExpressionType; export declare function maxOfExpressionTypes(types: ExpressionType[]): ExpressionType; /** Grants access to the expression properties of a FieldDef */ export interface HasExpression { e: Expr; } export declare function hasExpression(f: T): f is T & Expression & HasExpression; export type TemporalFieldType = 'date' | 'timestamp'; export declare function isTemporalType(s: string): s is TemporalFieldType; export type CastType = 'string' | 'number' | TemporalFieldType | 'boolean' | 'json'; export type AtomicFieldType = CastType | 'sql native' | 'record' | 'array' | 'error'; export declare function isAtomicFieldType(s: string): s is AtomicFieldType; export declare function canOrderBy(s: string): boolean; export declare function isCastType(s: string): s is CastType; /** * Fields which contain scalar data all inherit from this. The field * value could be an expression, and this is one of the objects * which might have an annotation. */ export interface FieldBase extends NamedObject, Expression, ResultMetadata { annotation?: Annotation; accessModifier?: NonDefaultAccessModifierLabel | undefined; requiresGroupBy?: RequiredGroupBy[]; ungroupings?: AggregateUngrouping[]; drillExpression?: Malloy.Expression | undefined; } export declare function fieldIsIntrinsic(f: FieldDef): f is AtomicFieldDef; export interface StringTypeDef { type: 'string'; bucketFilter?: string; bucketOther?: string; } export type StringFieldDef = StringTypeDef & AtomicFieldDef; export interface NumberTypeDef { type: 'number'; numberType?: 'integer' | 'float'; } export type NumberFieldDef = NumberTypeDef & AtomicFieldDef; export interface BooleanTypeDef { type: 'boolean'; } export type BooleanFieldDef = BooleanTypeDef & AtomicFieldDef; export interface JSONTypeDef { type: 'json'; } export type JSONFieldDef = JSONTypeDef & AtomicFieldDef; export interface NativeUnsupportedTypeDef { type: 'sql native'; rawType?: string; } export type NativeUnsupportedFieldDef = NativeUnsupportedTypeDef & AtomicFieldDef; export interface BasicArrayTypeDef { type: 'array'; elementTypeDef: Exclude; } export interface BasicArrayDef extends BasicArrayTypeDef, StructDefBase, JoinBase, FieldBase { type: 'array'; join: 'many'; } /** * Create a clean FieldDef from a TypeDef descendent * @param atd Usually a TypeDesc * @param name * @returns Field with `name` and no type meta data */ export declare function mkFieldDef(atd: AtomicTypeDef, name: string): AtomicFieldDef; export declare function mkArrayDef(ofType: AtomicTypeDef, name: string): ArrayDef; export interface RecordTypeDef { type: 'record'; fields: FieldDef[]; } export interface RecordDef extends RecordTypeDef, StructDefBase, JoinBase, FieldBase { type: 'record'; join: 'one'; queryTimezone?: string; } export interface RecordElementTypeDef { type: 'record_element'; } export interface RepeatedRecordTypeDef { type: 'array'; elementTypeDef: RecordElementTypeDef; fields: FieldDef[]; } export interface RepeatedRecordDef extends RepeatedRecordTypeDef, StructDefBase, JoinBase, FieldBase { type: 'array'; join: 'many'; queryTimezone?: string; } export type ArrayTypeDef = BasicArrayTypeDef | RepeatedRecordTypeDef; export type ArrayDef = BasicArrayDef | RepeatedRecordDef; export declare function isRepeatedRecordFunctionParam(paramT: FunctionParameterTypeDef): paramT is RepeatedRecordFunctionParameterTypeDef; export declare function isRepeatedRecord(fd: FieldDef | QueryFieldDef | StructDef | AtomicTypeDef): fd is RepeatedRecordTypeDef; export declare function isRecordOrRepeatedRecord(fd: FieldDef | StructDef): fd is RecordDef | RepeatedRecordDef; export declare function isBasicArray(td: AtomicTypeDef | FieldDef | QueryFieldDef | StructDef): td is BasicArrayTypeDef; export interface ErrorTypeDef { type: 'error'; } export type ErrorFieldDef = ErrorTypeDef & AtomicFieldDef; export type JoinType = 'one' | 'many' | 'cross'; export type JoinRelationship = 'one_to_one' | 'one_to_many' | 'many_to_one' | 'many_to_many'; export type MatrixOperation = 'left' | 'right' | 'full' | 'inner'; export declare function isMatrixOperation(x: string): x is MatrixOperation; export type JoinElementType = 'composite' | 'table' | 'sql_select' | 'query_source' | 'array' | 'record'; export interface JoinBase { type: JoinElementType; join: JoinType; matrixOperation?: MatrixOperation; onExpression?: Expr; fieldUsage?: FieldUsage[]; accessModifier?: NonDefaultAccessModifierLabel | undefined; } export type Joinable = CompositeSourceDef | TableSourceDef | SQLSourceDef | QuerySourceDef | RepeatedRecordDef | RecordDef | ArrayDef; export type JoinFieldDef = Joinable & JoinBase; export declare function isJoinable(sd: StructDef): sd is Joinable; export declare function isJoined(sd: TypedDef): sd is JoinFieldDef; export declare function isJoinedSource(sd: StructDef): sd is SourceDef & JoinBase; export type DateUnit = 'day' | 'week' | 'month' | 'quarter' | 'year'; export declare function isDateUnit(str: string): str is DateUnit; export type TimestampUnit = DateUnit | 'hour' | 'minute' | 'second'; export declare function isTimestampUnit(s: string): s is TimestampUnit; export type ExtractUnit = TimestampUnit | 'day_of_week' | 'day_of_year'; export declare function isExtractUnit(s: string): s is ExtractUnit; /** Value types distinguished by their usage in generated SQL, particularly with respect to filters. */ export declare enum ValueType { Date = "date", Timestamp = "timestamp", Number = "number", String = "string" } export type TimeValueType = ValueType.Date | ValueType.Timestamp; export interface DateTypeDef { type: 'date'; timeframe?: DateUnit; } export type DateFieldDef = DateTypeDef & AtomicFieldDef; export interface TimestampTypeDef { type: 'timestamp'; timeframe?: TimestampUnit; } export type TimestampFieldDef = TimestampTypeDef & AtomicFieldDef; /** parameter to order a query */ export interface OrderBy { field: string | number; dir?: 'asc' | 'desc'; } export interface FunctionOrderByExpression extends ExprE { node: 'functionOrderBy'; dir?: 'asc' | 'desc'; } export interface FunctionOrderByDefaultExpression extends ExprLeaf { node: 'functionDefaultOrderBy'; dir: 'asc' | 'desc'; } export type FunctionOrderBy = FunctionOrderByExpression | FunctionOrderByDefaultExpression; /** reference to a data source */ export type StructRef = string | SourceDef; export declare function refIsStructDef(ref: StructRef): ref is SourceDef; export type InvokedStructRef = { structRef: StructRef; sourceArguments?: Record; }; export interface Filtered { filterList?: FilterCondition[]; } /** * First element in a pipeline might be a reference to a turtle */ export interface TurtleSegment extends Filtered { name: string; } export interface Pipeline { pipeline: PipeSegment[]; } export interface Query extends Pipeline, Filtered, HasLocation { type?: 'query'; name?: string; structRef: StructRef; sourceArguments?: Record; annotation?: Annotation; modelAnnotation?: Annotation; compositeResolvedSourceDef?: SourceDef; } export type NamedQuery = Query & NamedObject; export type PipeSegment = QuerySegment | IndexSegment | RawSegment; export declare function segmentHasErrors(segment: PipeSegment): boolean; export declare function structHasErrors(struct: StructDef): boolean; export interface ReduceSegment extends QuerySegment { type: 'reduce'; } export declare function isReduceSegment(pe: PipeSegment): pe is ReduceSegment; export interface PartialSegment extends QuerySegment { type: 'partial'; } export declare function isPartialSegment(pe: PipeSegment): pe is PartialSegment; export interface ProjectSegment extends QuerySegment { type: 'project'; } export declare function isProjectSegment(pe: PipeSegment): pe is ProjectSegment; export declare function isQuerySegment(pe: PipeSegment): pe is QuerySegment; export type Sampling = SamplingRows | SamplingEnable | SamplingPercent; interface SamplingRows { rows: number; } export declare function isSamplingRows(s: Sampling): s is SamplingRows; interface SamplingPercent { percent: number; } export declare function isSamplingPercent(s: Sampling): s is SamplingPercent; interface SamplingEnable { enable: boolean; } export declare function isSamplingEnable(s: Sampling): s is SamplingEnable; export interface RawSegment extends Filtered { type: 'raw'; fields: never[]; referencedAt?: DocumentLocation; outputStruct: SourceDef; } export declare function isRawSegment(pe: PipeSegment): pe is RawSegment; export type IndexFieldDef = RefToField; export type SegmentFieldDef = IndexFieldDef | QueryFieldDef; /** * The compiler needs to know a number of things computed for a query. * We've modified the fieldUsage code from composite sources to collect * the information needed by the compiler and a query is processed * as a final step to append this information. * * 0) An ordered list list of active joins * 1) Each field that is referenced, even indirectly * 2) Each join path ending in a count * 3) Each join path ending in an assymmetric aggregate * 4) Each join path ending in an analytic funtion */ export interface SegmentUsageSummary { activeJoins?: FieldUsage[]; expandedFieldUsage?: FieldUsage[]; expandedUngroupings?: AggregateUngrouping[]; } export interface IndexSegment extends Filtered, SegmentUsageSummary { type: 'index'; indexFields: IndexFieldDef[]; limit?: number; weightMeasure?: string; sample?: Sampling; alwaysJoins?: string[]; fieldUsage?: FieldUsage[]; referencedAt?: DocumentLocation; outputStruct: SourceDef; } export declare function isIndexSegment(pe: PipeSegment): pe is IndexSegment; export interface FieldUsage { path: string[]; at?: DocumentLocation; uniqueKeyRequirement?: UniqueKeyRequirement; analyticFunctionUse?: boolean; } export declare function bareFieldUsage(fu: FieldUsage): boolean; export interface QuerySegment extends Filtered, Ordered, SegmentUsageSummary { type: 'reduce' | 'project' | 'partial'; queryFields: QueryFieldDef[]; extendSource?: FieldDef[]; limit?: number; queryTimezone?: string; alwaysJoins?: string[]; fieldUsage?: FieldUsage[]; referencedAt?: DocumentLocation; outputStruct: SourceDef; isRepeated: boolean; } export type NonDefaultAccessModifierLabel = 'private' | 'internal'; export type AccessModifierLabel = NonDefaultAccessModifierLabel | 'public'; export interface TurtleDef extends NamedObject, Pipeline { type: 'turtle'; annotation?: Annotation; accessModifier?: NonDefaultAccessModifierLabel | undefined; fieldUsage?: FieldUsage[]; requiredGroupBys?: string[][]; } export interface TurtleDefPlusFilters extends TurtleDef, Filtered { } interface StructDefBase extends HasLocation, NamedObject { type: string; annotation?: Annotation; modelAnnotation?: ModelAnnotation; fields: FieldDef[]; } export interface PartitionCompositeDesc { partitionField: string; partitions: { id: string; fields: string[]; }[]; compositeFields: string[]; } interface SourceDefBase extends StructDefBase, Filtered, ResultStructMetadata { arguments?: Record; parameters?: Record; queryTimezone?: string; connection: string; primaryKey?: PrimaryKeyRef; dialect: string; partitionComposite?: PartitionCompositeDesc; } /** which field is the primary key in this struct */ export type PrimaryKeyRef = string; export interface TableSourceDef extends SourceDefBase { type: 'table'; tablePath: string; } export interface CompositeSourceDef extends SourceDefBase { type: 'composite'; sources: SourceDef[]; } export interface SQLStringSegment { sql: string; } export type SQLPhraseSegment = Query | SQLStringSegment; export declare function isSegmentSQL(f: SQLPhraseSegment): f is SQLStringSegment; export interface SQLSourceDef extends SourceDefBase { type: 'sql_select'; selectStr: string; } export interface QuerySourceDef extends SourceDefBase { type: 'query_source'; query: Query; } export interface QueryResultDef extends SourceDefBase { type: 'query_result'; } export interface NestSourceDef extends SourceDefBase { type: 'nest_source'; pipeSQL: string; } export interface FinalizeSourceDef extends SourceDefBase { type: 'finalize'; } export declare function sourceBase(sd: SourceDefBase): SourceDefBase; export declare function isSourceDef(sd: NamedModelObject | FieldDef): sd is SourceDef; export type SourceDef = TableSourceDef | SQLSourceDef | QuerySourceDef | QueryResultDef | FinalizeSourceDef | NestSourceDef | CompositeSourceDef; /** Is this the "FROM" table of a query tree */ export declare function isBaseTable(def: StructDef): def is SourceDef; export type StructDef = SourceDef | RecordDef | ArrayDef; export type SourceComponentInfo = { type: 'table'; tableName: string; componentID?: string; sourceID?: string; } | { type: 'sql'; selectStatement: string; componentID?: string; sourceID?: string; }; export type TurtleType = 'turtle'; export type TurtleTypeDef = { type: 'turtle'; pipeline: PipeSegment[]; }; export type NonAtomicType = Exclude | 'null' | 'duration' | 'regular expression' | 'filter expression'; export interface NonAtomicTypeDef { type: NonAtomicType; } export type ExpressionValueType = AtomicFieldType | NonAtomicType | TurtleType; export type ExpressionValueTypeDef = AtomicTypeDef | NonAtomicTypeDef | TurtleTypeDef; export type BasicExpressionType = Exclude; export interface RequiredGroupBy { fieldUsage?: FieldUsage; at?: DocumentLocation; path: string[]; } export interface AggregateUngrouping { ungroupedFields: string[][] | '*'; fieldUsage: FieldUsage[]; requiresGroupBy?: RequiredGroupBy[]; exclude: boolean; path: string[]; refFields?: string[]; } export type TypeInfo = { expressionType: ExpressionType; evalSpace: EvalSpace; fieldUsage: FieldUsage[]; requiresGroupBy?: RequiredGroupBy[]; ungroupings?: AggregateUngrouping[]; }; export type TypeDesc = ExpressionValueTypeDef & TypeInfo; export type FunctionParameterTypeDef = ExpressionValueExtTypeDef; export type FunctionParamTypeDesc = FunctionParameterTypeDef & { expressionType: ExpressionType | undefined; evalSpace: EvalSpace; }; interface BasicArrayExtTypeDef { type: 'array'; elementTypeDef: Exclude, RecordExtTypeDef>; } type ExpressionValueExtTypeDef = AtomicTypeDef | NonAtomicTypeDef | TurtleTypeDef | BasicArrayExtTypeDef | RecordExtTypeDef | RepeatedRecordExtTypeDef | TypeExtensions; interface RecordExtTypeDef { type: 'record'; fields: ExtFieldDef[]; } type ExtFieldDef = FieldDef | (TypeExtensions & FieldBase); interface RepeatedRecordExtTypeDef { type: 'array'; elementTypeDef: RecordElementTypeDef; fields: ExtFieldDef[]; } type FunctionReturnTypeExtensions = GenericTypeDef; export type BasicArrayFunctionReturnTypeDef = BasicArrayExtTypeDef; export type FunctionReturnFieldDef = ExtFieldDef; export type RecordFunctionReturnTypeDef = RecordExtTypeDef; export type RepeatedRecordFunctionReturnTypeDef = RepeatedRecordExtTypeDef; type FunctionParameterTypeExtensions = GenericTypeDef | AnyTypeDef; export type BasicArrayFunctionParameterTypeDef = BasicArrayExtTypeDef; export type FunctionParameterFieldDef = ExtFieldDef; export type RecordFunctionParameterTypeDef = RecordExtTypeDef; export type RepeatedRecordFunctionParameterTypeDef = RepeatedRecordExtTypeDef; type FunctionGenericTypeExtensions = AnyTypeDef; export type BasicArrayFunctionGenericTypeDef = BasicArrayExtTypeDef; export type FunctionGenericFieldDef = ExtFieldDef; export type RecordFunctionGenericTypeDef = RecordExtTypeDef; export type RepeatedRecordFunctionGenericTypeDef = RepeatedRecordExtTypeDef; export interface GenericTypeDef { type: 'generic'; generic: string; } export interface AnyTypeDef { type: 'any'; } export type TypeDescExtensions = { expressionType: ExpressionType | undefined; evalSpace: EvalSpace; }; export type FunctionReturnTypeDef = ExpressionValueExtTypeDef; export type FunctionReturnTypeDesc = FunctionReturnTypeDef & TypeDescExtensions; export type EvalSpace = 'constant' | 'input' | 'output' | 'literal'; export declare function isLiteral(evalSpace: EvalSpace): evalSpace is "literal"; export declare function mergeEvalSpaces(...evalSpaces: EvalSpace[]): EvalSpace; export interface FunctionParameterDef { name: string; allowedTypes: FunctionParamTypeDesc[]; isVariadic: boolean; } export type FunctionGenericTypeDef = ExpressionValueExtTypeDef; export interface FunctionOverloadDef { returnType: FunctionReturnTypeDesc; isSymmetric?: boolean; params: FunctionParameterDef[]; supportsOrderBy?: boolean | 'only_default'; supportsLimit?: boolean; genericTypes?: { name: string; acceptibleTypes: FunctionGenericTypeDef[]; }[]; dialect: { [dialect: string]: { e: Expr; between?: { preceding: number | string; following: number | string; }; defaultOrderByArgIndex?: number; needsWindowOrderBy?: boolean; }; }; } export interface FunctionDef extends NamedObject { type: 'function'; overloads: FunctionOverloadDef[]; } export interface ConnectionDef extends NamedObject { type: 'connection'; } export type TemporalTypeDef = DateTypeDef | TimestampTypeDef; export type BasicAtomicTypeDef = StringTypeDef | TemporalTypeDef | NumberTypeDef | BooleanTypeDef | JSONTypeDef | NativeUnsupportedTypeDef | ErrorTypeDef; export type BasicAtomicDef = BasicAtomicTypeDef & FieldBase; export type AtomicTypeDef = BasicAtomicTypeDef | BasicArrayTypeDef | RecordTypeDef | RepeatedRecordTypeDef; export type AtomicFieldDef = BasicAtomicDef | BasicArrayDef | RecordDef | RepeatedRecordDef; export declare function isBasicAtomic(fd: FieldDef | QueryFieldDef | AtomicTypeDef): fd is BasicAtomicDef; export type FieldDef = BasicAtomicDef | JoinFieldDef | TurtleDef; export type FieldDefType = AtomicFieldType | 'turtle' | JoinElementType; export interface RefToField { type: 'fieldref'; path: string[]; annotation?: Annotation; at?: DocumentLocation; drillExpression?: Malloy.Expression | undefined; } export type QueryFieldDef = AtomicFieldDef | TurtleDef | RefToField; export type TypedDef = AtomicTypeDef | JoinFieldDef | TurtleDef | RefToField | StructDef; /** Get the output name for a NamedObject */ export declare function getIdentifier(n: AliasedName): string; export type NamedModelObject = SourceDef | NamedQuery | FunctionDef | ConnectionDef; export interface DependencyTree { [url: string]: DependencyTree; } /** Result of parsing a model file */ export interface ModelDef { name: string; exports: string[]; contents: Record; annotation?: ModelAnnotation; queryList: Query[]; dependencies: DependencyTree; references?: DocumentReference[]; imports?: ImportLocation[]; } /** Very common record type */ export type NamedSourceDefs = Record; export type NamedModelObjects = Record; /** Malloy source annotations attached to objects */ export interface Annotation { inherits?: Annotation; blockNotes?: Note[]; notes?: Note[]; } export interface Note { text: string; at: DocumentLocation; } /** Annotations with a uuid to make it easier to stream */ export interface ModelAnnotation extends Annotation { id: string; } export type QueryScalar = string | boolean | number | Date | Buffer | null; /** One value in one column of returned data. */ export type QueryValue = QueryScalar | QueryData | QueryDataRow; /** A row of returned data. */ export type QueryDataRow = { [columnName: string]: QueryValue; }; /** Returned query data. */ export type QueryData = QueryDataRow[]; /** Query execution stats. */ export type QueryRunStats = { queryCostBytes?: number; }; /** Returned Malloy query data */ export type MalloyQueryData = { rows: QueryDataRow[]; totalRows: number; runStats?: QueryRunStats; profilingUrl?: string; }; export interface DrillSource { sourceExplore: string; sourceFilters?: FilterCondition[]; sourceArguments?: Record; } export type QueryToMaterialize = { id: string; path: string; source: string | undefined; queryName: string; }; export interface CompiledQuery extends DrillSource { structs: SourceDef[]; sql: string; lastStageName: string; malloy: string; queryName?: string | undefined; connectionName: string; queryTimezone?: string; annotation?: Annotation; dependenciesToMaterialize?: Record; materialization?: QueryToMaterialize; defaultRowLimitAdded?: number; } /** Result type for running a Malloy query. */ export interface QueryResult extends CompiledQuery { result: QueryData; totalRows: number; error?: string; runStats?: QueryRunStats; profilingUrl?: string; } export declare function isTurtle(def: TypedDef): def is TurtleDef; export declare function isAtomic(def: TypedDef | ExpressionValueTypeDef): def is AtomicTypeDef; export interface SearchResultRow { field_name: string; field_value: string; weight: number; } export type SearchResult = SearchResultRow[]; export declare function isValueString(value: QueryValue, field: FieldDef): value is string | null; export declare function isValueNumber(value: QueryValue, field: FieldDef): value is number | null; export declare function isValueBoolean(value: QueryValue, field: FieldDef): value is boolean | null; export declare function isValueTimestamp(value: QueryValue, field: FieldDef): value is { value: string; } | null; export declare function isValueDate(value: QueryValue, field: FieldDef): value is { value: string; } | null; export interface SearchIndexResult { fieldName: string; fieldValue: string; fieldType: string; weight: number; } export interface SearchValueMapResult { fieldName: string; cardinality: number; values: { fieldValue: string; weight: number; }[]; } export interface PrepareResultOptions { replaceMaterializedReferences?: boolean; materializedTablePrefix?: string; defaultRowLimit?: number; isPartialQuery?: boolean; } type UTD = AtomicTypeDef | TypedDef | FunctionParameterTypeDef | FunctionReturnTypeDef | undefined; /** * A set of utilities for asking questions TypeDef/TypeDesc * (which is OK because TypeDesc is an extension of a TypeDef) */ export declare const TD: { isAtomic(td: UTD): td is AtomicTypeDef; isBasicAtomic(td: UTD): td is BasicAtomicTypeDef; isString: (td: UTD) => td is StringTypeDef; isNumber: (td: UTD) => td is NumberTypeDef; isBoolean: (td: UTD) => td is BooleanTypeDef; isJSON: (td: UTD) => td is JSONTypeDef; isSQL: (td: UTD) => td is NativeUnsupportedTypeDef; isDate: (td: UTD) => td is DateTypeDef; isTimestamp: (td: UTD) => td is TimestampTypeDef; isTemporal(td: UTD): td is TimestampTypeDef; isError: (td: UTD) => td is ErrorTypeDef; eq(x: UTD, y: UTD): boolean; }; /** * Aggregate functions carry this meta data. Used to determine if * a function requires the existence of a unique key. This used * be a pair of types: UniqueKeyUse and UniqueKeyPossibleUse. * * The three states are: * * 1. undefined - not recorded, symmetric MIN/MAX/COUNT_DISTINCT * 2. {isCount: true} - this is a COUNT aggregate * 3. {isCount: false} - this is an asymmetric aggregate, SUM or AVG */ export type UniqueKeyRequirement = undefined | { isCount: boolean; }; export declare function mergeUniqueKeyRequirement(existing: UniqueKeyRequirement, newInfo: UniqueKeyRequirement): UniqueKeyRequirement; export {};