Skip to content

Commit 55c4db4

Browse files
committed
pass compiler Id to transpilation native
1 parent 65a6e62 commit 55c4db4

File tree

4 files changed

+38
-15
lines changed

4 files changed

+38
-15
lines changed

packages/cubejs-backend-native/js/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export type SQLInterfaceOptions = {
104104
export interface TransformConfig {
105105
fileName: string;
106106
transpilers: string[];
107+
compilerId: string;
107108
metaData?: {
108109
cubeNames: string[];
109110
cubeSymbols: Record<string, Record<string, boolean>>;

packages/cubejs-backend-native/src/transpilers.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use neon::prelude::{JsPromise, JsResult, JsValue, NeonResult};
77
use neon::types::JsString;
88
use serde::Deserialize;
99
use std::collections::{HashMap, HashSet};
10-
use std::sync::RwLock;
10+
use std::sync::{LazyLock, RwLock};
1111

1212
#[derive(Deserialize, Default, Clone, Debug)]
1313
#[serde(rename_all = "camelCase")]
@@ -22,10 +22,12 @@ pub struct TransformMetaData {
2222
pub struct TransformRequestConfig {
2323
pub file_name: String,
2424
pub transpilers: Vec<Transpilers>,
25+
pub compiler_id: String,
2526
pub meta_data: Option<TransformMetaData>,
2627
}
2728

28-
static METADATA_CACHE: RwLock<Option<TransformMetaData>> = RwLock::new(None);
29+
static METADATA_CACHE: LazyLock<RwLock<HashMap<String, TransformMetaData>>> =
30+
LazyLock::new(|| RwLock::new(HashMap::new()));
2931

3032
pub fn register_module(cx: &mut ModuleContext) -> NeonResult<()> {
3133
cx.export_function("transpileJs", transpile_js)?;
@@ -57,17 +59,27 @@ pub fn transpile_js(mut cx: FunctionContext) -> JsResult<JsPromise> {
5759
cube_symbols: cache.cube_symbols.clone(),
5860
context_symbols: cache.context_symbols.clone(),
5961
};
60-
*config_lock = Some(cache);
62+
config_lock.insert(data.compiler_id.clone(), cache);
6163
cfg
6264
}
6365
None => {
64-
let cache = METADATA_CACHE.read().unwrap().clone().unwrap_or_default();
65-
TransformConfig {
66-
file_name: data.file_name,
67-
transpilers: data.transpilers,
68-
cube_names: cache.cube_names.clone(),
69-
cube_symbols: cache.cube_symbols.clone(),
70-
context_symbols: cache.context_symbols.clone(),
66+
let cache = METADATA_CACHE.read().unwrap();
67+
68+
match cache.get(&data.compiler_id) {
69+
Some(cached) => TransformConfig {
70+
file_name: data.file_name,
71+
transpilers: data.transpilers,
72+
cube_names: cached.cube_names.clone(),
73+
cube_symbols: cached.cube_symbols.clone(),
74+
context_symbols: cached.context_symbols.clone(),
75+
},
76+
None => TransformConfig {
77+
file_name: data.file_name,
78+
transpilers: data.transpilers,
79+
cube_names: HashSet::new(),
80+
cube_symbols: HashMap::new(),
81+
context_symbols: HashMap::new(),
82+
},
7183
}
7284
}
7385
},

packages/cubejs-schema-compiler/src/compiler/DataSchemaCompiler.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class DataSchemaCompiler {
4646
this.yamlCompiler.dataSchemaCompiler = this;
4747
this.pythonContext = null;
4848
this.workerPool = null;
49+
this.compilerId = options.compilerId;
4950
}
5051

5152
compileObjects(compileServices, objects, errorsReport) {
@@ -97,6 +98,7 @@ export class DataSchemaCompiler {
9798

9899
const transpilationWorkerThreads = getEnv('transpilationWorkerThreads');
99100
const transpilationNative = getEnv('transpilationNative');
101+
const { compilerId } = this;
100102

101103
if (!transpilationNative && transpilationWorkerThreads) {
102104
const wc = getEnv('transpilationWorkerThreadsCount');
@@ -141,9 +143,9 @@ export class DataSchemaCompiler {
141143
content: ';',
142144
};
143145

144-
await this.transpileJsFile(dummyFile, errorsReport, { cubeNames, cubeSymbols, transpilerNames, contextSymbols: CONTEXT_SYMBOLS });
146+
await this.transpileJsFile(dummyFile, errorsReport, { cubeNames, cubeSymbols, transpilerNames, contextSymbols: CONTEXT_SYMBOLS, compilerId });
145147

146-
results = await Promise.all(toCompile.map(f => this.transpileFile(f, errorsReport, { transpilerNames })));
148+
results = await Promise.all(toCompile.map(f => this.transpileFile(f, errorsReport, { transpilerNames, compilerId })));
147149
} else if (transpilationWorkerThreads) {
148150
results = await Promise.all(toCompile.map(f => this.transpileFile(f, errorsReport, { cubeNames, cubeSymbols, transpilerNames })));
149151
} else {
@@ -172,7 +174,11 @@ export class DataSchemaCompiler {
172174
content: ';',
173175
};
174176

175-
return this.transpileJsFile(dummyFile, errorsReport, { cubeNames: [], cubeSymbols: {}, transpilerNames: [], contextSymbols: {} });
177+
return this.transpileJsFile(
178+
dummyFile,
179+
errorsReport,
180+
{ cubeNames: [], cubeSymbols: {}, transpilerNames: [], contextSymbols: {}, compilerId: this.compilerId }
181+
);
176182
} else if (transpilationWorkerThreads && this.workerPool) {
177183
this.workerPool.terminate();
178184
}
@@ -219,12 +225,13 @@ export class DataSchemaCompiler {
219225
}
220226
}
221227

222-
async transpileJsFile(file, errorsReport, { cubeNames, cubeSymbols, contextSymbols, transpilerNames }) {
228+
async transpileJsFile(file, errorsReport, { cubeNames, cubeSymbols, contextSymbols, transpilerNames, compilerId }) {
223229
try {
224230
if (getEnv('transpilationNative')) {
225231
const reqData = {
226232
fileName: file.fileName,
227233
transpilers: transpilerNames,
234+
compilerId,
228235
...(cubeNames && {
229236
metaData: {
230237
cubeNames,

packages/cubejs-schema-compiler/src/compiler/PrepareCompiler.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ export const prepareCompiler = (repo: SchemaFileRepository, options: PrepareComp
5959
transpilers.push(new CubeCheckDuplicatePropTranspiler());
6060
}
6161

62+
const compilerId = uuidv4();
63+
6264
const compiler = new DataSchemaCompiler(repo, Object.assign({}, {
6365
cubeNameCompilers: [cubeDictionary],
6466
preTranspileCubeCompilers: [cubeSymbols, cubeValidator],
@@ -80,6 +82,7 @@ export const prepareCompiler = (repo: SchemaFileRepository, options: PrepareComp
8082
standalone: options.standalone,
8183
nativeInstance,
8284
yamlCompiler,
85+
compilerId,
8386
}, options));
8487

8588
return {
@@ -90,7 +93,7 @@ export const prepareCompiler = (repo: SchemaFileRepository, options: PrepareComp
9093
joinGraph,
9194
compilerCache,
9295
headCommitId: options.headCommitId,
93-
compilerId: uuidv4(),
96+
compilerId,
9497
};
9598
};
9699

0 commit comments

Comments
 (0)