From 5f2ab262d27084221f11794224e65aa44987a771 Mon Sep 17 00:00:00 2001 From: George Kastrinis Date: Tue, 3 Sep 2024 21:11:33 +0300 Subject: [PATCH] [Rel v0.2] Migrate Java SDK files (#46) --- rai-sdk-examples/src/test/resources/hello.rel | 2 +- .../src/main/java/com/relationalai/Client.java | 16 ++++++++-------- .../test/java/com/relationalai/DatabaseTest.java | 4 ++-- .../test/java/com/relationalai/LoadCsvTest.java | 8 ++++---- .../test/java/com/relationalai/LoadJsonTest.java | 2 +- .../test/java/com/relationalai/ModelsTest.java | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/rai-sdk-examples/src/test/resources/hello.rel b/rai-sdk-examples/src/test/resources/hello.rel index f1dc7997..569f2d19 100644 --- a/rai-sdk-examples/src/test/resources/hello.rel +++ b/rai-sdk-examples/src/test/resources/hello.rel @@ -1 +1 @@ -def R = "hello", "world" \ No newline at end of file +def R {("hello", "world")} diff --git a/rai-sdk/src/main/java/com/relationalai/Client.java b/rai-sdk/src/main/java/com/relationalai/Client.java index 7a0f76d1..0b2b2f54 100644 --- a/rai-sdk/src/main/java/com/relationalai/Client.java +++ b/rai-sdk/src/main/java/com/relationalai/Client.java @@ -973,16 +973,16 @@ static void genSchemaConfig(StringBuilder builder, CsvOptions options) { if (schema == null || schema.isEmpty()) return; var count = 0; - builder.append("def config:schema ="); + builder.append("def config[:schema]: {"); for (var entry : schema.entrySet()) { if (count > 0) builder.append(';'); var k = entry.getKey(); var v = entry.getValue(); - builder.append(String.format("\n :%s, \"%s\"", k, v)); + builder.append(String.format("\n (:%s, \"%s\")", k, v)); count++; } - builder.append('\n'); + builder.append("}\n"); } // Returns a Rel literal for the given value. @@ -1013,7 +1013,7 @@ static void genSyntaxOption(StringBuilder builder, String name, Object value) { if (value == null) return; var lit = genLiteral(value); - var def = String.format("def config:syntax:%s = %s\n", name, lit); + var def = String.format("def config[:syntax, :%s]: %s\n", name, lit); builder.append(def); } @@ -1032,8 +1032,8 @@ static String genLoadCsv(String relation, CsvOptions options) { var builder = new StringBuilder(); genSchemaConfig(builder, options); genSyntaxConfig(builder, options); - builder.append("def config:data = data\n"); - builder.append(String.format("def insert:%s = load_csv[config]", relation)); + builder.append("def config[:data]: data\n"); + builder.append(String.format("def insert[:%s]: load_csv[config]", relation)); return builder.toString(); } @@ -1071,8 +1071,8 @@ public TransactionResult loadCsv( // Generate the Rel to load JSON data into a relation. static String genLoadJson(String relation) { var builder = new StringBuilder(); - builder.append("def config:data = data\n"); - builder.append(String.format("def insert:%s = load_json[config]", relation)); + builder.append("def config[:data]: data\n"); + builder.append(String.format("def insert[:%s]: load_json[config]", relation)); return builder.toString(); } diff --git a/rai-sdk/src/test/java/com/relationalai/DatabaseTest.java b/rai-sdk/src/test/java/com/relationalai/DatabaseTest.java index 51f6293a..cba612a6 100644 --- a/rai-sdk/src/test/java/com/relationalai/DatabaseTest.java +++ b/rai-sdk/src/test/java/com/relationalai/DatabaseTest.java @@ -107,7 +107,7 @@ void testDatabase() throws HttpError, InterruptedException, IOException { } static final String testModel = - "def R = \"hello\", \"world\""; + "def R {(\"hello\", \"world\")}"; static final String testJson = "{" + "\"name\":\"Amira\",\n" + @@ -159,7 +159,7 @@ void testDatabase() throws HttpError, InterruptedException, IOException { assertEquals(databaseCloneName, createRsp.name); assertEquals("CREATED", createRsp.state); - // Make sure the data was cloned + // Make sure the data was cloned var rsp = client.executeV1(databaseCloneName, engineName, "test_data", true); Relation rel; diff --git a/rai-sdk/src/test/java/com/relationalai/LoadCsvTest.java b/rai-sdk/src/test/java/com/relationalai/LoadCsvTest.java index 59529548..4609482a 100644 --- a/rai-sdk/src/test/java/com/relationalai/LoadCsvTest.java +++ b/rai-sdk/src/test/java/com/relationalai/LoadCsvTest.java @@ -49,7 +49,7 @@ public class LoadCsvTest extends UnitTest { assertEquals(0, loadRsp.output.length); assertEquals(0, loadRsp.problems.length); - var rsp = client.executeV1(databaseName, engineName, "def output = sample"); + var rsp = client.executeV1(databaseName, engineName, "def output {sample}"); Relation rel; @@ -105,7 +105,7 @@ public class LoadCsvTest extends UnitTest { assertEquals(0, loadRsp.output.length); assertEquals(0, loadRsp.problems.length); - var rsp = client.executeV1(databaseName, engineName, "def output = sample_no_header"); + var rsp = client.executeV1(databaseName, engineName, "def output {sample_no_header}"); Relation rel; @@ -162,7 +162,7 @@ public class LoadCsvTest extends UnitTest { assertEquals(0, loadRsp.output.length); assertEquals(0, loadRsp.problems.length); - var rsp = client.executeV1(databaseName, engineName, "def output = sample_alt_syntax"); + var rsp = client.executeV1(databaseName, engineName, "def output {sample_alt_syntax}"); Relation rel; @@ -216,7 +216,7 @@ public class LoadCsvTest extends UnitTest { assertEquals(0, loadRsp.output.length); assertEquals(0, loadRsp.problems.length); - var rsp = client.executeV1(databaseName, engineName, "def output = sample"); + var rsp = client.executeV1(databaseName, engineName, "def output {sample}"); Relation rel; diff --git a/rai-sdk/src/test/java/com/relationalai/LoadJsonTest.java b/rai-sdk/src/test/java/com/relationalai/LoadJsonTest.java index 6324292a..e74e6dc7 100644 --- a/rai-sdk/src/test/java/com/relationalai/LoadJsonTest.java +++ b/rai-sdk/src/test/java/com/relationalai/LoadJsonTest.java @@ -47,7 +47,7 @@ public class LoadJsonTest extends UnitTest { assertEquals(0, loadRsp.output.length); assertEquals(0, loadRsp.problems.length); - var rsp = client.executeV1(databaseName, engineName, "def output = sample"); + var rsp = client.executeV1(databaseName, engineName, "def output {sample}"); Relation rel; diff --git a/rai-sdk/src/test/java/com/relationalai/ModelsTest.java b/rai-sdk/src/test/java/com/relationalai/ModelsTest.java index 36443629..f80143fb 100644 --- a/rai-sdk/src/test/java/com/relationalai/ModelsTest.java +++ b/rai-sdk/src/test/java/com/relationalai/ModelsTest.java @@ -32,7 +32,7 @@ @TestInstance(Lifecycle.PER_CLASS) @ExtendWith({TestExtension.class}) public class ModelsTest extends UnitTest { - static final String testModel = "def R = \"hello\", \"world\""; + static final String testModel = "def R {(\"hello\", \"world\")}"; @Test void testModels() throws HttpError, InterruptedException, IOException { var client = createClient();