import { Database, Statement, QueryResults } from "sql.js"; import { RelationObject, DielConfig, TableMetaData, DbType, ExecutionSpec } from "./runtimeTypes"; import { OriginalRelation, SelectionUnit, DbIdType, LogicalTimestep, RelationNameType, DerivedRelation, DielAst, Relation } from "../parser/dielAstTypes"; import Visitor from "../parser/generateAst"; import { DielPhysicalExecution } from "../compiler/DielPhysicalExecution"; import DbEngine from "./DbEngine"; export declare let STRICT: boolean; export declare let LOGINFO: boolean; export declare const INIT_TIMESTEP = 1; export declare const SqliteMasterQuery = "\n SELECT sql, name\n FROM sqlite_master\n WHERE type='table'\n AND sql not null\n AND name != 'sqlite_sequence'"; declare type ReactFunc = (v: any) => void; declare type TickBind = { outputName: string; uiUpdateFunc: ReactFunc; }; declare class ViewConstraintQuery { viewName: string; queries: string[][]; } export declare type MetaDataPhysical = Map; declare type DbMetaData = { dbType: DbType; }; export declare type PhysicalMetaData = { cache?: boolean; dbs: Map; relationLocation: Map; }; export declare type RelationShippingFuncType = (view: string, o: RelationObject, requestTimestep?: number) => void; export default class DielRuntime { timestep: LogicalTimestep; eventByTimestep: Map; ast: DielAst; physicalExecution: DielPhysicalExecution; dbEngines: Map; physicalMetaData: PhysicalMetaData; config: DielConfig; staticRelationsSent: { static: RelationNameType; output: RelationNameType; }[]; db: Database; scales: RelationObject; visitor: Visitor; constraintQueries: Map; checkConstraints: boolean; protected boundFns: TickBind[]; protected runtimeOutputs: Map; protected runtimeInputs: Map; cache: Map; constructor(config: DielConfig); getEventByTimestep(timestep: LogicalTimestep): string; ShutDown(): void; /** * When the notebook invokes BindOutput it can invoke the data to be evaluated * @param outputName * @param reactFn * @param triggerEval */ BindOutput(outputName: string, reactFn: ReactFunc): void; /** * GetView need to know if it's dependent on an event table * in which case it will go and fetch the depdent events which are NOT depent on inputs * it will also remember if this was done before * add these special cases into physical execution logic * @param view */ GetView(view: string): RelationObject; NewInputMany: RelationShippingFuncType; NewInput(i: string, o: any, requestTimestep?: number): void; private makeSubKey; /** * Improvements: could be smarter * @param eventView */ private getCacheKey; /** * Returns the requestTimestep corresponding to the cached requestTimestep. * If cache miss, will return the requestTimestep passed in. * @param eventView * @param requestTimestep */ private getFromCacheOrMiss; private newInputHelper; private runOutputsGivenNewInputForEvent; /** * this is the execution logic * where we do distributed query execution * and possibly materialization (basically can be in SQL triggers or our own even handling layer) */ runOutput(b: TickBind): void; /** * Check view constraints afresh and report if broken */ constraintChecking(viewName: string): void; downloadDB(dbId?: DbIdType, fileName?: string): void; simpleGetLocal(view: string): RelationObject | null; private setup; initialCompile(): Promise; setupRemotes(): Promise; AddUDF(fName: string): void; private setupUDFs; /** * returns false if caching is not enabled or that it's a cache miss * - if the cache misses, then ship to everywhere * - if cache does not miss, then insert into reference directly (not an event) * - we have to do this for every view because the same view might be triggered by multiple inputs * @param inputName * @param timestep */ checkAndApplyCache(eventName: RelationNameType, relationsDependentOnCurrentEvent: Set, timestep: number): RelationNameType[]; /** * @param inputName * @param timestep */ shipWorkerInput(inputName: string, notCachedViews: RelationNameType[], timestep: number): void; private findRemoteDbEngine; /** * returns the DIEL code that will be ran to register the tables */ private setupMainDb; /** * output tables HAVE to be local tables * since they are synchronous --- if they are over other tables * it would be handled via some trigger programs * FIXME: just pass in what it needs, the name str */ private setupNewOutput; private setupNewInput; private dbPrepare; /** * returns the results as an array of objects (sql.js) */ ExecuteSqlAst(ast: SelectionUnit): RelationObject; ExecuteStringQuery(q: string): RelationObject; incrementalExecuteToDb(instructions: ExecutionSpec): Promise; executeToDBs(): Promise; GetScales(output: string, component?: string): { dimension: number; x: string; y?: string; z?: string; }; /** * Returns the name of derived view (which will be auto generated if not specified) * @param q: the raw query string * @param rName: the relation name */ AddOutputRelationByString(q: string, rName?: string): Promise; AddRelation(r: Relation): void; DeleteView(foundIdx: number): void; AddOriginalTableByAst(rDef: OriginalRelation): Promise; AddTemplateByString(q: string): Promise; GetRelationDef(rName: string): Relation; /** * Note that the AST here need not be typed or de-stared * It's fine if they are. * #OPTIMIZE: In the future, we can skip some of the compiling steps if its already normalized */ AddViewByAst(derived: DerivedRelation): Promise; inspectQueryResult(query: string): QueryResults; /** * Check if the view constraint query is broken. If so, report what records broke them. * @param query * @param viewName * @param constraint */ reportConstraintQueryResult(query: string, viewName: string, constraint: string): void; } export {}; //# sourceMappingURL=DielRuntime.d.ts.map