Skip to content

Commit 9086be4

Browse files
committed
feat(native): Initial support for cube.py (Python configuration) (#6465)
1 parent 01f93f1 commit 9086be4

File tree

27 files changed

+1219
-64
lines changed

27 files changed

+1219
-64
lines changed

packages/cubejs-backend-native/Cargo.lock

Lines changed: 128 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cubejs-backend-native/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ log = "=0.4.11"
2424
simple_logger = "1.7.0"
2525
uuid = { version = "0.8", features = ["v4"] }
2626
once_cell = "1.10"
27+
pyo3 = { version = "0.18.3", features = [] }
28+
pyo3-asyncio = { version = "0.18.0", features = ["tokio-runtime"] }
29+
convert_case = "0.4"
2730

2831
[dependencies.neon]
2932
version = "=0.10.0"

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,30 @@ export const shutdownInterface = async (instance: SqlInterfaceInstance): Promise
238238

239239
await new Promise((resolve) => setTimeout(resolve, 2000));
240240
}
241+
242+
interface PyConfiguration {
243+
checkAuth?: (req: unknown, authorization: string) => Promise<void>
244+
queryRewrite?: (query: unknown, ctx: unknown) => Promise<unknown>
245+
}
246+
247+
export const pythonLoadConfig = async (context: string, options: { file: string }): Promise<PyConfiguration> => {
248+
const native = loadNative();
249+
const config = await native.pythonLoadConfig(context, options);
250+
251+
if (config.checkAuth) {
252+
const nativeCheckAuth = config.checkAuth;
253+
config.checkAuth = async (req: any, authorization: string) => {
254+
return nativeCheckAuth(
255+
// Req is a large object, let's simplify it
256+
{
257+
url: req.url,
258+
method: req.method,
259+
headers: req.headers,
260+
},
261+
authorization
262+
);
263+
};
264+
}
265+
266+
return config;
267+
}

packages/cubejs-backend-native/package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
"install": "node-pre-gyp install || echo 'Your system is not supported by @cubejs-backend/native, some feature will be unavailable.'",
1919
"upload-binary-cross": "mkdir -p native && cp index.node native/index.node && node-pre-gyp package --target_arch=$PACKAGE_TARGET_ARCH --target_platform=$PACKAGE_TARGET_PLATFORM --target_libc=$PACKAGE_TARGET_LIBC && node-pre-gyp-github publish",
2020
"upload-binary": "mkdir -p native && cp index.node native/index.node && node-pre-gyp package && node-pre-gyp-github publish",
21-
"test:server": "CUBEJS_NATIVE_INTERNAL_DEBUG=true CUBESQL_LOG_LEVEL=trace CUBESQL_PG_PORT=5555 node test/server.js",
22-
"test:server:stream": "CUBESQL_STREAM_MODE=true CUBESQL_LOG_LEVEL=error CUBESQL_PG_PORT=5555 node test/server.js",
23-
"test:unit": "jest --forceExit test",
21+
"test:server": "CUBEJS_NATIVE_INTERNAL_DEBUG=true CUBESQL_LOG_LEVEL=trace CUBESQL_PG_PORT=5555 node dist/test/server.js",
22+
"test:server:stream": "CUBESQL_STREAM_MODE=true CUBESQL_LOG_LEVEL=error CUBESQL_PG_PORT=5555 node dist/test/server.js",
23+
"test:python": "CUBEJS_NATIVE_INTERNAL_DEBUG=true CUBESQL_LOG_LEVEL=trace CUBESQL_PG_PORT=5555 node dist/test/python.js",
24+
"test:unit": "jest --forceExit",
2425
"test:cargo": "cargo test"
2526
},
2627
"engines": {
@@ -56,8 +57,10 @@
5657
"testEnvironment": "node",
5758
"verbose": true,
5859
"roots": [
59-
"<rootDir>/js/",
60-
"<rootDir>/test/"
60+
"<rootDir>/dist/test/"
61+
],
62+
"setupFilesAfterEnv": [
63+
"<rootDir>/dist/test/setup/index.js"
6164
]
6265
},
6366
"license": "Apache-2.0",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

0 commit comments

Comments
 (0)