import * as ast from "./Ast"; import type { AstNodeMetadata } from "./types"; export type Statement = CreateMaterializedView | Explain; export interface CreateMaterializedView { type: "create_materialized_view"; name: string; select: Select; metadata?: CreateMaterializedViewMetadata; } export interface CreateMaterializedViewMetadata { displayName?: string; description?: string; tags?: string[]; refreshSchedule?: string; expire?: string; writeMode?: QueryWriteMode; extendedStats?: QueryExtendedStats; partitionedBy?: QueryPartitionedByEntry[]; clusterType?: "shared" | "dedicated"; } export type QueryWriteMode = "append" | "overwrite"; export type QueryExtendedStats = "all" | "none"; export type QueryPartitionedByEntry = { field: string; transform: string; }; export interface Explain { type: "explain"; query: Select; } export interface Select { type: "select"; budget: ast.NqlBudget | null; columns: Output[]; deduplication: Deduplication | Raw | null; from: Table[] | Raw; where: BooleanExpression | Raw | null; } export type Output = ColumnRef | Lit | Func | Raw | ast.NqlPlaceholder; export type Expression = BooleanExpression | ColumnRef | Lit | Func | Raw | ast.NqlPlaceholder; export interface Raw { type: "nql"; as?: string; nql: string; } export interface Deduplication { type: "deduplication"; expressions: Expression[]; } export type ColumnRef = AttributeRef | DatasetColumnRef | RawRef; export type BooleanExpression = And | Between | Equals | NotEquals | Gt | Gte | In | IsNull | Like | Lt | Lte | Not | Or; export interface PlaceholderTable extends ast.NqlPlaceholder { join?: Join; } export type Table = RosettaTable | DatasetTable | RawTable | PlaceholderTable; export interface RosettaTable { type: "rosetta_stone"; as?: string; join?: Join; } export interface DatasetTable { type: "dataset"; as?: string; datasetId: number; join?: Join; } export interface RawTable { type: "raw_table"; as?: string; nql: string; join?: Join; } export interface Join { type: "join"; condition: BooleanExpression | Raw | null; conditionType: ast.NqlJoinConditionType; joinType: ast.NqlJoinType; } export interface AttributeRef { type: "attribute_ref"; as?: string; name: string; column: string; } export interface DatasetColumnRef { type: "dataset_column_ref"; as?: string; column: string; datasetId: number; } export interface RawRef { type: "raw_ref"; as?: string; nql: string; } export interface Lit { type: "lit"; as?: string; value_type: ast.NqlSimpleType; value: string | null; } export interface Func { type: "function"; as?: string; name: string; args: Expression[]; } export interface And { type: "and"; as?: string; operands: Expression[]; } export interface Or { type: "or"; as?: string; operands: Expression[]; } export interface Not { type: "not"; as?: string; operand: BooleanExpression | Raw; } /** Implicitly we only support asymmetric betweens. */ export interface Between { type: "between"; as?: string; operand: Expression; lower: Expression; upper: Expression; } export interface Equals { type: "="; as?: string; left: Expression; right: Expression; } export interface NotEquals { type: "<>"; as?: string; left: Expression; right: Expression; } export interface Lt { type: "<"; as?: string; left: Expression; right: Expression; } export interface Lte { type: "<="; as?: string; left: Expression; right: Expression; } export interface Gt { type: ">"; as?: string; left: Expression; right: Expression; } export interface Gte { type: ">="; as?: string; left: Expression; right: Expression; } export interface In { type: "in"; as?: string; negated: boolean; expression: Expression; values: Expression[] | Raw; } export interface IsNull { type: "is_null"; as?: string; negated: boolean; operand: Expression; } export interface Like { type: "like"; as?: string; negated: boolean; value: Expression; pattern: string; } export type Node = (Select | Expression | Deduplication | Table | BooleanExpression | Join | AttributeRef | DatasetColumnRef | RawRef | Lit | And | Or | Not | Between | Equals | NotEquals | Lt | Lte | Gt | Gte | In | IsNull | Like | Raw) & { ast_metadata?: AstNodeMetadata; }; export declare function parseStatement(n: ast.NqlAst): Statement | Raw; export declare function parseCreateMaterializedView(n: ast.NqlCreateMaterializedView): CreateMaterializedView; export declare function parseExplain(n: ast.NqlExplain): Explain | Raw; export declare function parseSelect(n: ast.NqlSelect): Select; export declare function parseFrom(n: ast.NqlAst): Table[]; export declare function parseWhere(n: ast.NqlAst): BooleanExpression | Raw; export declare function parseDeduplication(n: ast.NqlSelect): Deduplication | Raw | null; export declare function parseExpression(n: ast.NqlAst): Expression; export declare function parseOutput(n: ast.NqlAst): Output; export declare function extractPlaceholders(n: Node): Node[];