Skip to content

Commit

Permalink
[Rel v0.2] Migrate Javascript SDK files (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkastrinis authored Sep 3, 2024
1 parent d5fda38 commit f6a8eeb
Show file tree
Hide file tree
Showing 11 changed files with 408 additions and 406 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ $ npm run example -- ./examples/listEngines.ts
```

```console
$ npm run example -- ./examples/runQuery.ts -d dbName -e engineName -c "def output = 1 + 2"
$ npm run example -- ./examples/runQuery.ts -d dbName -e engineName -c "def output {1 + 2}"
```

## Data Types
Expand Down
2 changes: 1 addition & 1 deletion examples/hello.rel
Original file line number Diff line number Diff line change
@@ -1 +1 @@
def R = "hello", "world"
def R {("hello", "world")}
4 changes: 2 additions & 2 deletions src/api/model/modelApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('ModelApi', () => {

it('should installModel', async () => {
const testModels: Model[] = [
{ name: 'test_model_1', value: 'def foo = :bar' },
{ name: 'test_model_1', value: 'def foo {:bar}' },
];
const resp = await client.installModels(
databaseName,
Expand All @@ -68,7 +68,7 @@ describe('ModelApi', () => {

it('should deleteModel', async () => {
const testModels: Model[] = [
{ name: 'test_model_2', value: 'def foo = :bar' },
{ name: 'test_model_2', value: 'def foo {:bar}' },
];
let resp = await client.installModels(
databaseName,
Expand Down
16 changes: 8 additions & 8 deletions src/api/model/modelApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export class ModelApi extends ExecAsyncApi {
models.map((model, index) => {
const inputName = `input_${randInt}_${index}`;
queryInputs.push({ name: inputName, value: model.value });
queries.push(`def delete:rel:catalog:model["${model.name}"] = rel:catalog:model["${model.name}"]
def insert:rel:catalog:model["${model.name}"] = ${inputName}`);
queries.push(`def delete[:rel, :catalog, :model, "${model.name}"]: rel[:catalog, :model, "${model.name}"]
def insert[:rel, :catalog, :model, "${model.name}"]: ${inputName}`);
});

return await this.exec(
Expand All @@ -48,8 +48,8 @@ export class ModelApi extends ExecAsyncApi {
models.map((model, index) => {
const inputName = `input_${randInt}_${index}`;
queryInputs.push({ name: inputName, value: model.value });
queries.push(`def delete:rel:catalog:model["${model.name}"] = rel:catalog:model["${model.name}"]
def insert:rel:catalog:model["${model.name}"] = ${inputName}`);
queries.push(`def delete[:rel, :catalog, :model, "${model.name}"]: rel[:catalog, :model, "${model.name}"]
def insert[:rel, :catalog, :model, "${model.name}"]: ${inputName}`);
});

return await this.execAsync(
Expand All @@ -67,7 +67,7 @@ export class ModelApi extends ExecAsyncApi {
const rsp = await this.exec(
database,
engine,
`def output:${outName}[name] = rel:catalog:model(name, _)`,
`def output(:${outName}, name): rel(:catalog, :model, name, _)`,
);

const result = rsp.results.find(
Expand All @@ -86,7 +86,7 @@ export class ModelApi extends ExecAsyncApi {
const rsp = await this.exec(
database,
engine,
`def output:${outName} = rel:catalog:model["${name}"]`,
`def output[:${outName}]: rel[:catalog, :model, "${name}"]`,
);

const result = rsp.results.find(
Expand All @@ -106,15 +106,15 @@ export class ModelApi extends ExecAsyncApi {
async deleteModels(database: string, engine: string, names: string[]) {
const queries = names.map(
name =>
`def delete:rel:catalog:model["${name}"] = rel:catalog:model["${name}"]`,
`def delete[:rel, :catalog, :model, "${name}"]: rel[:catalog, :model, "${name}"]`,
);
return await this.exec(database, engine, queries.join('\n'), [], false);
}

async deleteModelsAsync(database: string, engine: string, names: string[]) {
const queries = names.map(
name =>
`def delete:rel:catalog:model["${name}"] = rel:catalog:model["${name}"]`,
`def delete[:rel, :catalog, :model, "${name}"]: rel[:catalog, :model, "${name}"]`,
);

return await this.execAsync(
Expand Down
8 changes: 4 additions & 4 deletions src/api/query/execAsyncApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ export class ExecAsyncApi extends TransactionAsyncApi {
json: any,
) {
const qs = [
`def config:data = data`,
`def insert:${relation} = load_json[config]`,
`def config[:data]: data`,
`def insert[:${relation}]: load_json[config]`,
];
const inputs: QueryInput[] = [
{
Expand All @@ -138,7 +138,7 @@ export class ExecAsyncApi extends TransactionAsyncApi {
syntax?: CsvConfigSyntax,
schema?: CsvConfigSchema,
) {
const qs = [`def config:data = data`];
const qs = [`def config[:data]: data`];
const inputs: QueryInput[] = [
{
name: 'data',
Expand All @@ -154,7 +154,7 @@ export class ExecAsyncApi extends TransactionAsyncApi {
qs.push(...schemaToRel(schema));
}

qs.push(`def insert:${relation} = load_csv[config]`);
qs.push(`def insert[:${relation}]: load_csv[config]`);

return this.exec(database, engine, qs.join('\n'), inputs, false);
}
Expand Down
8 changes: 4 additions & 4 deletions src/api/query/loadData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Load data integration tests', () => {
resp = await client.exec(
databaseName,
engineName,
'def output = test_relation',
'def output {test_relation}',
);

expect(resp.transaction.state).toEqual('COMPLETED');
Expand All @@ -74,7 +74,7 @@ describe('Load data integration tests', () => {
resp = await client.exec(
databaseName,
engineName,
'def output = test_relation',
'def output {test_relation}',
);

expect(resp.transaction.state).toEqual('COMPLETED');
Expand Down Expand Up @@ -109,7 +109,7 @@ describe('Load data integration tests', () => {
resp = await client.exec(
databaseName,
engineName,
'def output = test_relation_1',
'def output {test_relation_1}',
);

expect(resp.transaction.state).toEqual('COMPLETED');
Expand Down Expand Up @@ -142,7 +142,7 @@ describe('Load data integration tests', () => {
resp = await client.exec(
databaseName,
engineName,
'def output = test_relation_2',
'def output {test_relation_2}',
);

expect(resp.transaction.state).toEqual('COMPLETED');
Expand Down
8 changes: 4 additions & 4 deletions src/api/query/queryApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('QueryApi', () => {
persist: [],
inputs: [],
source: {
value: 'def output = 123',
value: 'def output {123}',
name: 'query',
type: 'Source',
path: '',
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('QueryApi', () => {
})
.reply(200, response);

const result = await api.query(database, engine, 'def output = 123');
const result = await api.query(database, engine, 'def output {123}');

scope.done();

Expand All @@ -119,7 +119,7 @@ describe('QueryApi', () => {
},
],
source: {
value: 'def output = 123',
value: 'def output {123}',
name: 'query',
type: 'Source',
path: '',
Expand All @@ -146,7 +146,7 @@ describe('QueryApi', () => {
compute_name: engine,
})
.reply(200, response);
const result = await api.query(database, engine, 'def output = 123', [
const result = await api.query(database, engine, 'def output {123}', [
{ name: 'input1', value: 'value1' },
]);

Expand Down
8 changes: 5 additions & 3 deletions src/api/query/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ export function syntaxToRel(syntax: CsvConfigSyntax) {
return `(${key}, :${toRelLiteral(syntax.header![key])})`;

Check warning on line 86 in src/api/query/utils.ts

View workflow job for this annotation

GitHub Actions / sdk

Forbidden non-null assertion
})
.join('; ');
qs.push(`def config:syntax:header = ${headerStr}`);
qs.push(`def config[:syntax, :header]: { ${headerStr} }`);
} else {
qs.push(`def config:syntax:${prop} = ${toRelLiteral(syntax[prop])}`);
qs.push(`def config[:syntax, :${prop}]: ${toRelLiteral(syntax[prop])}`);
}
});

Expand All @@ -99,7 +99,9 @@ export function schemaToRel(schema: CsvConfigSchema) {
const qs: string[] = [];

Object.keys(schema).forEach(colName => {
qs.push(`def config:schema${colName} = ${toRelLiteral(schema[colName])}`);
qs.push(
`def config[:schema, ${colName}]: ${toRelLiteral(schema[colName])}`,
);
});

return qs;
Expand Down
6 changes: 3 additions & 3 deletions src/api/transaction/transactionAsyncApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ const protobufMock = readFileSync(__dirname + '/mocks/metadata.pb');
const multipartContentType =
'multipart/form-data; boundary=28deee55b43d20e109a8fe119e47c5393620ea568b7059405c4cf23bad7b';

// def output = :foo
// def output = :"foo;bar", 1
// def output = 1
// def output {:foo}
// def output {(:"foo;bar", 1)}
// def output {1}
const expectedArrow = [
{
filename: '0.arrow',
Expand Down
2 changes: 1 addition & 1 deletion src/results/resultTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class ResultTable implements IteratorOf<RelTypedValue['value'][]> {
* Instantiate a new ResultTable instance.
*
* @example
* cosnt result = await client.exec('database', 'engine', 'def output = 123, "test"')
* cosnt result = await client.exec('database', 'engine', 'def output {123}, "test"')
* cosnt table = new ResultTable(result.results[0]);
*
* console.log(table.values()); // Prints [[123n, "test"]];
Expand Down
Loading

0 comments on commit f6a8eeb

Please sign in to comment.