Skip to content

Commit

Permalink
datacube: minor cleanup to cached source model
Browse files Browse the repository at this point in the history
  • Loading branch information
akphi committed Feb 14, 2025
1 parent 9f2e800 commit e127942
Show file tree
Hide file tree
Showing 7 changed files with 777 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,17 @@ export class LegendDataCubeDataCubeCacheManager {
const table = `${LegendDataCubeDataCubeCacheManager.TABLE_NAME_PREFIX}${LegendDataCubeDataCubeCacheManager.tableCounter}`;
const csvFileName = `${LegendDataCubeDataCubeCacheManager.CSV_FILE_NAME}${LegendDataCubeDataCubeCacheManager.tableCounter}.csv`;

const connection = await this.database.connect();

const columnNames: string[] = [];
result.builder.columns.forEach((col) => columnNames.push(col.name));

const data = result.result.rows.map((row) => row.values);

const csv = csvStringify([columnNames, ...data], {
const csvContent = csvStringify([columnNames, ...data], {
escapeChar: `'`,
quoteChar: `'`,
});
await this.database.registerFileText(csvFileName, csvContent);

await this._database?.registerFileText(csvFileName, csv);

const connection = await this.database.connect();
await connection.insertCSVFromPath(csvFileName, {
schema: schema,
name: table,
Expand All @@ -115,7 +112,6 @@ export class LegendDataCubeDataCubeCacheManager {
quote: `'`,
delimiter: ',',
});

await connection.close();

return { table, schema, rowCount: result.result.rows.length };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import {
PackageableElementPointerType,
DatabaseType,
PRIMITIVE_TYPE,
V1_serializePureModelContextData,
} from '@finos/legend-graph';
import {
_elementPtr,
Expand Down Expand Up @@ -615,7 +616,7 @@ export class LegendDataCubeDataCubeEngine extends DataCubeEngine {
const cachedSource = new CachedDataCubeSource();
cachedSource.columns = source.columns;
cachedSource.query = query;
cachedSource.model = model;
cachedSource.model = V1_serializePureModelContextData(model);
cachedSource.runtime = packageableRuntime.path;
cachedSource.db = database.path;
cachedSource.schema = schema.name;
Expand All @@ -639,7 +640,7 @@ export class LegendDataCubeDataCubeEngine extends DataCubeEngine {
} else if (source instanceof LegendQueryDataCubeSource) {
return this._getLambdaRelationType(query, source.model);
} else if (source instanceof CachedDataCubeSource) {
return this._getLambdaRelationType(query, serialize(source.model));
return this._getLambdaRelationType(query, source.model);
}
throw new UnsupportedOperationError(
`Can't get relation type for lambda with unsupported source`,
Expand Down Expand Up @@ -696,7 +697,7 @@ export class LegendDataCubeDataCubeEngine extends DataCubeEngine {

private async _generateExecutionPlan(
query: V1_Lambda,
model: V1_PureModelContext,
model: PlainObject<V1_PureModelContext>,
parameterValues?: V1_ParameterValue[] | undefined,
options?: DataCubeExecutionOptions | undefined,
): Promise<V1_ExecutionPlan> {
Expand All @@ -709,7 +710,7 @@ export class LegendDataCubeDataCubeEngine extends DataCubeEngine {
? PureClientVersion.VX_X_X
: undefined),
function: this.serializeValueSpecification(query),
model: serialize(model),
model,
context: serialize(
V1_rawBaseExecutionContextModelSchema,
new V1_RawBaseExecutionContext(),
Expand Down
Loading

0 comments on commit e127942

Please sign in to comment.