Skip to content

Commit 522711d

Browse files
authored
Merge pull request #6 from RelationalAI/hnr-async-protocol
Adding support to async protocol
2 parents 22f8bbf + 8e024e8 commit 522711d

File tree

17 files changed

+666
-17
lines changed

17 files changed

+666
-17
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
## main
3+
* Added support to the asynchronous protocol including:
4+
- `executeAsync`: runs an asynchronous request.
5+
- `executeAsyncWait`: runs an asynchronous request and wait of its completion.
6+
- `getTransaction`: gets information about transaction.
7+
- `getTransactions`: gets the list of transactions.
8+
- `getTransactionResults`: gets transaction execution results.
9+
- `getTransactionMetadata`: gets transaction metadata.
10+
- `getTransactionProblems`: gets transaction execution problems.
11+
* Added `ExecuteAsyncTest` test class
12+
13+
## v0.0.1
14+
* initial release

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ In order to use the `rai-sdk-java`, you need add this dependency to your project
8686
<dependency>
8787
<groupId>com.relationalai</groupId>
8888
<artifactId>rai-sdk</artifactId>
89-
<version>0.0.1</version>
89+
<version>0.0.2</version>
9090
</dependency>
9191

9292
You need also to point maven to the SDK GitHub packages repository in the project's POM:

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<description>The RelationalAI Software Development Kit (SDK) for Java</description>
2222
<groupId>com.relationalai</groupId>
2323
<artifactId>rai-sdk-pom</artifactId>
24-
<version>0.0.1</version>
24+
<version>0.0.2</version>
2525
<packaging>pom</packaging>
2626
<url></url>
2727

rai-sdk-examples/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<parent>
2121
<groupId>com.relationalai</groupId>
2222
<artifactId>rai-sdk-pom</artifactId>
23-
<version>0.0.1</version>
23+
<version>0.0.2</version>
2424
</parent>
2525

2626
<name>RelationalAI SDK for Java Examples</name>

rai-sdk-examples/src/main/java/com/relationalai/examples/Execute.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ String getCommand() throws IOException {
4141
return null;
4242
}
4343

44-
// todo: schema
4544
public void parseArgs(String[] args) {
4645
var c = Command.create("Execute")
4746
.addArgument("database")
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2022 RelationalAI, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"): you may
5+
* not use this file except in compliance with the License. You may obtain
6+
* a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
17+
package com.relationalai.examples;
18+
19+
import java.io.IOException;
20+
import java.nio.file.Files;
21+
import java.nio.file.Path;
22+
import com.relationalai.Client;
23+
import com.relationalai.Config;
24+
import com.relationalai.HttpError;
25+
import com.relationalai.Json;
26+
27+
public class ExecuteAsync implements Runnable {
28+
boolean readonly;
29+
String database, engine, command, filename, profile;
30+
31+
// Returns the name of the file, without extension.
32+
static String readFile(String fname) throws IOException {
33+
return Files.readAllBytes(Path.of(fname)).toString();
34+
}
35+
36+
String getCommand() throws IOException {
37+
if (command != null)
38+
return command; // prefer command line
39+
if (filename != null)
40+
return readFile(filename);
41+
return null;
42+
}
43+
44+
public void parseArgs(String[] args) {
45+
var c = Command.create("ExecuteAsync")
46+
.addArgument("database")
47+
.addArgument("engine")
48+
.addOption("c", "rel source string")
49+
.addOption("f", "rel source file")
50+
.addFlag("readonly", "readonly query (default: false)")
51+
.parseArgs(args);
52+
this.database = c.getValue("database");
53+
this.engine = c.getValue("engine");
54+
this.command = c.getValue("c");
55+
this.filename = c.getValue("f");
56+
this.readonly = c.getValue("readonly", Boolean.class);
57+
this.profile = c.getValue("profile");
58+
}
59+
60+
public void run(String[] args) throws HttpError, InterruptedException, IOException {
61+
parseArgs(args);
62+
var cfg = Config.loadConfig("~/.rai/config", profile);
63+
var client = new Client(cfg);
64+
String source = getCommand();
65+
if (source == null)
66+
return; // nothing to execute
67+
var rsp = client.executeAsync(database, engine, source, readonly);
68+
Json.print(rsp);
69+
}
70+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2022 RelationalAI, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"): you may
5+
* not use this file except in compliance with the License. You may obtain
6+
* a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
17+
package com.relationalai.examples;
18+
19+
import com.relationalai.Client;
20+
import com.relationalai.Config;
21+
import com.relationalai.HttpError;
22+
import com.relationalai.Json;
23+
24+
import java.io.IOException;
25+
26+
public class GetTransaction implements Runnable {
27+
String id, profile;
28+
29+
public void parseArgs(String[] args) {
30+
var c = Command.create("GetTransaction")
31+
.addArgument("id")
32+
.addOption("profile", "config profile (default: default)")
33+
.parseArgs(args);
34+
this.id = c.getValue("id");
35+
this.profile = c.getValue("profile");
36+
}
37+
38+
public void run(String[] args) throws HttpError, InterruptedException, IOException {
39+
parseArgs(args);
40+
var cfg = Config.loadConfig("~/.rai/config", profile);
41+
var client = new Client(cfg);
42+
43+
var rsp = client.getTransaction(id);
44+
Json.print(rsp);
45+
}
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2022 RelationalAI, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"): you may
5+
* not use this file except in compliance with the License. You may obtain
6+
* a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
17+
package com.relationalai.examples;
18+
19+
import com.relationalai.Client;
20+
import com.relationalai.Config;
21+
import com.relationalai.HttpError;
22+
import com.relationalai.Json;
23+
24+
import java.io.IOException;
25+
26+
public class GetTransactionMetadata implements Runnable {
27+
String id, profile;
28+
29+
public void parseArgs(String[] args) {
30+
var c = Command.create("GetTransactionMetadata")
31+
.addArgument("id")
32+
.addOption("profile", "config profile (default: default)")
33+
.parseArgs(args);
34+
this.id = c.getValue("id");
35+
this.profile = c.getValue("profile");
36+
}
37+
38+
public void run(String[] args) throws HttpError, InterruptedException, IOException {
39+
parseArgs(args);
40+
var cfg = Config.loadConfig("~/.rai/config", profile);
41+
var client = new Client(cfg);
42+
43+
var rsp = client.getTransactionMetadata(id);
44+
Json.print(rsp);
45+
}
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2022 RelationalAI, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"): you may
5+
* not use this file except in compliance with the License. You may obtain
6+
* a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
17+
package com.relationalai.examples;
18+
19+
import com.relationalai.Client;
20+
import com.relationalai.Config;
21+
import com.relationalai.HttpError;
22+
import com.relationalai.Json;
23+
24+
import java.io.IOException;
25+
26+
public class GetTransactionProblems implements Runnable {
27+
String id, profile;
28+
29+
public void parseArgs(String[] args) {
30+
var c = Command.create("GetTransactionProblems")
31+
.addArgument("id")
32+
.addOption("profile", "config profile (default: default)")
33+
.parseArgs(args);
34+
this.id = c.getValue("id");
35+
this.profile = c.getValue("profile");
36+
}
37+
38+
public void run(String[] args) throws HttpError, InterruptedException, IOException {
39+
parseArgs(args);
40+
var cfg = Config.loadConfig("~/.rai/config", profile);
41+
var client = new Client(cfg);
42+
43+
var rsp = client.getTransactionProblems(id);
44+
Json.print(rsp);
45+
}
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2022 RelationalAI, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"): you may
5+
* not use this file except in compliance with the License. You may obtain
6+
* a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
17+
package com.relationalai.examples;
18+
19+
import com.relationalai.Client;
20+
import com.relationalai.Config;
21+
import com.relationalai.HttpError;
22+
import com.relationalai.Json;
23+
24+
import java.io.IOException;
25+
26+
public class GetTransactionResults implements Runnable {
27+
String id, profile;
28+
29+
public void parseArgs(String[] args) {
30+
var c = Command.create("GetTransactionResults")
31+
.addArgument("id")
32+
.addOption("profile", "config profile (default: default)")
33+
.parseArgs(args);
34+
this.id = c.getValue("id");
35+
this.profile = c.getValue("profile");
36+
}
37+
38+
public void run(String[] args) throws HttpError, InterruptedException, IOException {
39+
parseArgs(args);
40+
var cfg = Config.loadConfig("~/.rai/config", profile);
41+
var client = new Client(cfg);
42+
43+
var rsp = client.getTransactionResults(id);
44+
Json.print(rsp);
45+
}
46+
}

0 commit comments

Comments
 (0)