From 48082b560f676119d83a7f58e5ea8370f6c7ba5e Mon Sep 17 00:00:00 2001 From: joshua Date: Mon, 13 Nov 2023 10:11:30 +0000 Subject: [PATCH 1/2] Updates for 2.25.6 driver and server --- README.md | 25 ++-- build.gradle | 6 +- .../osi/loader/config/Configuration.java | 8 +- .../config/ConfigurationValidation.java | 28 ++-- .../generator/AppendAttributeGenerator.java | 18 +-- ...AppendAttributeOrInsertThingGenerator.java | 20 +-- .../loader/generator/AttributeGenerator.java | 6 +- .../osi/loader/generator/EntityGenerator.java | 10 +- .../osi/loader/generator/Generator.java | 2 +- .../loader/generator/RelationGenerator.java | 48 +++---- .../osi/loader/loader/AsyncLoaderWorker.java | 10 +- .../osi/loader/loader/TypeDBLoader.java | 24 ++-- .../typedb/osi/loader/util/GeneratorUtil.java | 6 +- .../typedb/osi/loader/util/TypeDBUtil.java | 74 ++++++----- .../vaticle/typedb/osi/loader/util/Util.java | 4 +- .../osi/loader/cli/TypeDBLoaderCLITest.java | 12 +- .../config/ConfigurationValidationTest.java | 36 +++--- .../AppendAttributeGeneratorTest.java | 12 +- ...ndAttributeOrInsertThingGeneratorTest.java | 12 +- .../generator/AttributeGeneratorTest.java | 12 +- .../loader/generator/EntityGeneratorTest.java | 20 +-- .../generator/RelationGeneratorTest.java | 20 +-- .../osi/loader/loader/TypeDBLoaderTest.java | 121 +++++++++--------- .../typedb/osi/loader/util/QueryUtilTest.java | 2 +- 24 files changed, 267 insertions(+), 269 deletions(-) diff --git a/README.md b/README.md index 9b54508..5663de7 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ --- --- -### +### [![TypeDB Loader Test](https://github.com/bayer-science-for-a-better-life/grami/actions/workflows/testandbuild.yaml/badge.svg)](https://github.com/bayer-science-for-a-better-life/grami/actions/workflows/testandbuild.yaml) [![TypeDB Loader Build](https://github.com/bayer-science-for-a-better-life/grami/actions/workflows/release.yaml/badge.svg)](https://github.com/bayer-science-for-a-better-life/grami/actions/workflows/release.yaml) @@ -153,17 +153,18 @@ To connect to TypeDB Cluster, a set of options is provided: ## Compatibility Table -Ranges are [inclusive, exclusive). - -| TypeDB Loader | TypeDB Client (internal) | TypeDB | TypeDB Cluster | -|:-------------:|:------------------------:|:---------------:|:---------------:| -| 1.7.0 | 2.18.1 | 2.18.x - | 2.18.x - | -| 1.6.0 | 2.14.2 | 2.14.x - 2.17.x | 2.14.x - 2.16.x | -| 1.2.0 - 1.6.0 | 2.8.0 - 2.14.0 | 2.8.0 - 2.14.0 | N/A | -| 1.1.0 - 1.2.0 | 2.8.0 | 2.8.x | N/A | -| 1.0.0 | 2.5.0 - 2.7.1 | 2.5.x - 2.7.x | N/A | -| 0.1.1 | 2.0.0 - 2.5.0 | 2.0.x - 2.4.x | N/A | -| <0.1 | 1.8.0 | 1.8.x | N/A | +Ranges are [inclusive, inclusive]. + +| TypeDB Loader | TypeDB Driver (internal) | TypeDB | TypeDB Cluster | +|:-------------:|:----------------------:|:---------------:|:---------------:| +| 1.8.0 | 2.24.15 | 2.24.x - | 2.24.x - | +| 1.7.0 | 2.18.1 | 2.18.x 2.23.x | 2.18.x 2.23.x | +| 1.6.0 | 2.14.2 | 2.14.x - 2.17.x | 2.14.x - 2.16.x | +| 1.2.0 - 1.5.x | 2.8.0 - 2.14.0 | 2.8.0 - 2.14.0 | N/A | +| 1.1.0 - 1.1.x | 2.8.0 | 2.8.x | N/A | +| 1.0.0 | 2.5.0 - 2.7.1 | 2.5.x - 2.7.x | N/A | +| 0.1.1 | 2.0.0 - 2.4.x | 2.0.x - 2.4.x | N/A | +| <0.1 | 1.8.0 | 1.8.x | N/A | * [Type DB](https://github.com/vaticle/typedb) diff --git a/build.gradle b/build.gradle index e85f12e..d0b60d6 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group 'com.vaticle.typedb-osi' -version '1.7.0' +version '1.8.0' repositories { mavenCentral() @@ -15,8 +15,8 @@ repositories { } dependencies { - implementation("com.vaticle.typedb:typedb-client:2.18.1") - implementation("com.vaticle.typeql:typeql-lang:2.18.0") + implementation("com.vaticle.typedb:typedb-driver:2.25.2") + implementation("com.vaticle.typeql:typeql-lang:2.25.0") implementation("com.google.code.gson:gson:2.8.6") implementation("org.slf4j:slf4j-api:1.7.25") implementation("org.apache.logging.log4j:log4j-api:2.17.1") diff --git a/src/main/java/com/vaticle/typedb/osi/loader/config/Configuration.java b/src/main/java/com/vaticle/typedb/osi/loader/config/Configuration.java index 2f23fa9..9ee60a1 100644 --- a/src/main/java/com/vaticle/typedb/osi/loader/config/Configuration.java +++ b/src/main/java/com/vaticle/typedb/osi/loader/config/Configuration.java @@ -16,9 +16,9 @@ package com.vaticle.typedb.osi.loader.config; -import com.vaticle.typedb.client.api.TypeDBSession; -import com.vaticle.typedb.client.api.TypeDBTransaction; -import com.vaticle.typedb.client.api.answer.ConceptMap; +import com.vaticle.typedb.driver.api.TypeDBSession; +import com.vaticle.typedb.driver.api.TypeDBTransaction; +import com.vaticle.typedb.driver.api.answer.ConceptMap; import com.vaticle.typedb.osi.loader.type.AttributeValueType; import com.vaticle.typeql.lang.TypeQL; @@ -39,7 +39,7 @@ public class Configuration { public static AttributeValueType getValueType(TypeDBSession session, String conceptType) { AttributeValueType valueType = null; try (TypeDBTransaction txn = session.transaction(TypeDBTransaction.Type.READ)) { - Set answers = txn.query().match(TypeQL.match(TypeQL.cVar("t").type(conceptType)).get(TypeQL.cVar("t"))).collect(Collectors.toSet()); + Set answers = txn.query().get(TypeQL.match(TypeQL.cVar("t").type(conceptType)).get(TypeQL.cVar("t"))).collect(Collectors.toSet()); assert answers.size() == 1; for (ConceptMap answer : answers) { valueType = AttributeValueType.valueOf(answer.get("t").asAttributeType().getValueType().name()); diff --git a/src/main/java/com/vaticle/typedb/osi/loader/config/ConfigurationValidation.java b/src/main/java/com/vaticle/typedb/osi/loader/config/ConfigurationValidation.java index e7d8fe8..363f151 100644 --- a/src/main/java/com/vaticle/typedb/osi/loader/config/ConfigurationValidation.java +++ b/src/main/java/com/vaticle/typedb/osi/loader/config/ConfigurationValidation.java @@ -16,13 +16,13 @@ package com.vaticle.typedb.osi.loader.config; -import com.vaticle.typedb.client.api.TypeDBSession; -import com.vaticle.typedb.client.api.TypeDBTransaction; -import com.vaticle.typedb.client.api.answer.ConceptMap; -import com.vaticle.typedb.client.common.exception.TypeDBClientException; +import com.vaticle.typedb.driver.api.TypeDBSession; +import com.vaticle.typedb.driver.api.TypeDBTransaction; +import com.vaticle.typedb.driver.api.answer.ConceptMap; +import com.vaticle.typedb.driver.common.exception.TypeDBDriverException; import com.vaticle.typedb.osi.loader.util.Util; import com.vaticle.typeql.lang.TypeQL; -import com.vaticle.typeql.lang.query.TypeQLMatch; +import com.vaticle.typeql.lang.query.TypeQLGet; import java.io.FileNotFoundException; import java.io.IOException; @@ -377,15 +377,15 @@ private boolean valConceptTypeInSchema(HashMap> valida String conceptType, String breadcrumbConceptType) { boolean exists = false; - TypeQLMatch query = TypeQL.match(TypeQL.cVar("t").type(conceptType)); + TypeQLGet query = TypeQL.match(TypeQL.cVar("t").type(conceptType)).get(); try (TypeDBTransaction txn = session.transaction(TypeDBTransaction.Type.READ)) { - Util.trace(Integer.toString((int) txn.query().match(query).count())); + Util.trace(Integer.toString((int) txn.query().get(query).count())); exists = true; - } catch (TypeDBClientException typeDBClientException) { - if (typeDBClientException.toString().contains("Invalid Type Read: The type '" + conceptType + "' does not exist.")) { + } catch (TypeDBDriverException typeDBDriverException) { + if (typeDBDriverException.toString().contains("Invalid Type Read: The type '" + conceptType + "' does not exist.")) { validationReport.get("errors").add(breadcrumbs + "." + breadcrumbConceptType + ": <" + conceptType + "> does not exist in schema"); } else { - throw typeDBClientException; + throw typeDBDriverException; } } return exists; @@ -532,9 +532,9 @@ private void valRoleType(HashMap> validationReport, String breadcrumbs, String relationType, String roleType) { - TypeQLMatch query = TypeQL.match(TypeQL.type(relationType).relates(TypeQL.cVar("r"))).get(TypeQL.cVar("r")); + TypeQLGet query = TypeQL.match(TypeQL.type(relationType).relates(TypeQL.cVar("r"))).get(TypeQL.cVar("r")); try (TypeDBTransaction txn = session.transaction(TypeDBTransaction.Type.READ)) { - Stream answers = txn.query().match(query); + Stream answers = txn.query().get(query); if (answers.noneMatch(a -> a.get("r").asRoleType().getLabel().name().equals(roleType))) { validationReport.get("errors").add(breadcrumbs + ".role: <" + roleType + "> is not a role for relation of type <" + relationType + "> in schema"); } @@ -547,9 +547,9 @@ private void valRolePlayedByConcept(HashMap> validatio String relationType, String role, String conceptType) { - TypeQLMatch query = TypeQL.match(TypeQL.cVar("c").plays(relationType, role)).get(TypeQL.cVar("c")); + TypeQLGet query = TypeQL.match(TypeQL.cVar("c").plays(relationType, role)).get(TypeQL.cVar("c")); try (TypeDBTransaction txn = session.transaction(TypeDBTransaction.Type.READ)) { - Stream answers = txn.query().match(query); + Stream answers = txn.query().get(query); if (answers.noneMatch(c -> c.get("c").asThingType().getLabel().name().equals(conceptType))) { validationReport.get("errors").add(breadcrumbs + ".role: <" + role + "> is not player by <" + conceptType + "> in relation of type <" + relationType + "> in schema"); } diff --git a/src/main/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeGenerator.java b/src/main/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeGenerator.java index abce249..bf2084c 100644 --- a/src/main/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeGenerator.java +++ b/src/main/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeGenerator.java @@ -16,18 +16,18 @@ package com.vaticle.typedb.osi.loader.generator; -import com.vaticle.typedb.client.api.TypeDBTransaction; -import com.vaticle.typedb.client.api.answer.ConceptMap; -import com.vaticle.typedb.client.common.exception.TypeDBClientException; +import com.vaticle.typedb.driver.api.TypeDBTransaction; +import com.vaticle.typedb.driver.api.answer.ConceptMap; +import com.vaticle.typedb.driver.common.exception.TypeDBDriverException; import com.vaticle.typedb.osi.loader.config.Configuration; import com.vaticle.typedb.osi.loader.io.FileLogger; import com.vaticle.typedb.osi.loader.util.GeneratorUtil; import com.vaticle.typedb.osi.loader.util.TypeDBUtil; import com.vaticle.typedb.osi.loader.util.Util; import com.vaticle.typeql.lang.TypeQL; +import com.vaticle.typeql.lang.builder.ConceptVariableBuilder; import com.vaticle.typeql.lang.pattern.constraint.ThingConstraint; -import com.vaticle.typeql.lang.pattern.variable.ThingVariable; -import com.vaticle.typeql.lang.pattern.variable.UnboundConceptVariable; +import com.vaticle.typeql.lang.pattern.statement.ThingStatement; import com.vaticle.typeql.lang.query.TypeQLInsert; import org.apache.commons.io.FilenameUtils; import org.apache.logging.log4j.LogManager; @@ -75,7 +75,7 @@ public void write(TypeDBTransaction tx, String[] row, boolean allowMultiInsert) } else { safeInsert(tx, query, answers, allowMultiInsert, filePath, originalRow, dataLogger); } - } catch (TypeDBClientException typeDBClientException) { + } catch (TypeDBDriverException typeDBDriverException) { FileLogger.getLogger().logUnavailable(fileName, originalRow); dataLogger.error("TypeDB Unavailable - Row in <" + filePath + "> not inserted - written to <" + fileNoExtension + "_unavailable.log" + ">"); } @@ -87,7 +87,7 @@ public void write(TypeDBTransaction tx, String[] row, boolean allowMultiInsert) public TypeQLInsert generateMatchInsertStatement(String[] row) { if (row.length > 0) { - ThingVariable.Thing entityMatchStatement = TypeQL.cVar("thing") + ThingStatement.Thing entityMatchStatement = TypeQL.cVar("thing") .isa(appendConfiguration.getMatch().getType()); for (Configuration.Definition.Attribute consAtt : appendConfiguration.getMatch().getOwnerships()) { ArrayList constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute( @@ -97,8 +97,8 @@ public TypeQLInsert generateMatchInsertStatement(String[] row) { } } - UnboundConceptVariable insertUnboundVar = TypeQL.cVar("thing"); - ThingVariable.Thing insertStatement = null; + ConceptVariableBuilder insertUnboundVar = TypeQL.cVar("thing"); + ThingStatement.Thing insertStatement = null; for (Configuration.Definition.Attribute attributeToAppend : appendConfiguration.getInsert().getOwnerships()) { ArrayList constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute( row, header, filePath, fileSeparator, attributeToAppend); diff --git a/src/main/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeOrInsertThingGenerator.java b/src/main/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeOrInsertThingGenerator.java index 82ff874..fcf02b8 100644 --- a/src/main/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeOrInsertThingGenerator.java +++ b/src/main/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeOrInsertThingGenerator.java @@ -16,18 +16,18 @@ package com.vaticle.typedb.osi.loader.generator; -import com.vaticle.typedb.client.api.TypeDBTransaction; -import com.vaticle.typedb.client.api.answer.ConceptMap; -import com.vaticle.typedb.client.common.exception.TypeDBClientException; +import com.vaticle.typedb.driver.api.TypeDBTransaction; +import com.vaticle.typedb.driver.api.answer.ConceptMap; +import com.vaticle.typedb.driver.common.exception.TypeDBDriverException; import com.vaticle.typedb.osi.loader.config.Configuration; import com.vaticle.typedb.osi.loader.io.FileLogger; import com.vaticle.typedb.osi.loader.util.GeneratorUtil; import com.vaticle.typedb.osi.loader.util.TypeDBUtil; import com.vaticle.typedb.osi.loader.util.Util; import com.vaticle.typeql.lang.TypeQL; +import com.vaticle.typeql.lang.builder.ConceptVariableBuilder; import com.vaticle.typeql.lang.pattern.constraint.ThingConstraint; -import com.vaticle.typeql.lang.pattern.variable.ThingVariable; -import com.vaticle.typeql.lang.pattern.variable.UnboundConceptVariable; +import com.vaticle.typeql.lang.pattern.statement.ThingStatement; import com.vaticle.typeql.lang.query.TypeQLInsert; import org.apache.commons.io.FilenameUtils; import org.apache.logging.log4j.LogManager; @@ -81,7 +81,7 @@ public void write(TypeDBTransaction tx, String[] row, boolean allowMultiInsert) } else { safeInsert(tx, appendQuery, answers, allowMultiInsert, filePath, originalRow, dataLogger); } - } catch (TypeDBClientException typeDBClientException) { + } catch (TypeDBDriverException typeDBDriverException) { FileLogger.getLogger().logUnavailable(fileName, originalRow); dataLogger.error("TypeDB Unavailable - Row in <" + filePath + "> not inserted - written to <" + fileNoExtension + "_unavailable.log" + ">"); } @@ -97,7 +97,7 @@ public void write(TypeDBTransaction tx, String[] row, boolean allowMultiInsert) public TypeQLInsert generateMatchInsertStatement(String[] row) { if (row.length > 0) { - ThingVariable.Thing entityMatchStatement = TypeQL.cVar("thing") + ThingStatement.Thing entityMatchStatement = TypeQL.cVar("thing") .isa(appendOrInsertConfiguration.getMatch().getType()); for (Configuration.Definition.Attribute ownershipThingGetter : appendOrInsertConfiguration.getMatch().getOwnerships()) { ArrayList constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute( @@ -107,8 +107,8 @@ public TypeQLInsert generateMatchInsertStatement(String[] row) { } } - UnboundConceptVariable insertUnboundVar = TypeQL.cVar("thing"); - ThingVariable.Thing insertStatement = null; + ConceptVariableBuilder insertUnboundVar = TypeQL.cVar("thing"); + ThingStatement.Thing insertStatement = null; for (Configuration.Definition.Attribute attributeToAppend : appendOrInsertConfiguration.getInsert().getOwnerships()) { ArrayList constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute( row, header, filePath, fileSeparator, attributeToAppend); @@ -133,7 +133,7 @@ public TypeQLInsert generateMatchInsertStatement(String[] row) { public TypeQLInsert generateThingInsertStatement(String[] row) { if (row.length > 0) { - ThingVariable.Thing insertStatement = GeneratorUtil.generateBoundThingVar(appendOrInsertConfiguration.getMatch().getType()); + ThingStatement.Thing insertStatement = GeneratorUtil.generateBoundThingVar(appendOrInsertConfiguration.getMatch().getType()); for (Configuration.Definition.Attribute attribute : appendOrInsertConfiguration.getMatch().getOwnerships()) { ArrayList constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute( diff --git a/src/main/java/com/vaticle/typedb/osi/loader/generator/AttributeGenerator.java b/src/main/java/com/vaticle/typedb/osi/loader/generator/AttributeGenerator.java index 2a2315e..11feb0b 100644 --- a/src/main/java/com/vaticle/typedb/osi/loader/generator/AttributeGenerator.java +++ b/src/main/java/com/vaticle/typedb/osi/loader/generator/AttributeGenerator.java @@ -16,8 +16,8 @@ package com.vaticle.typedb.osi.loader.generator; -import com.vaticle.typedb.client.api.TypeDBTransaction; -import com.vaticle.typedb.client.common.exception.TypeDBClientException; +import com.vaticle.typedb.driver.api.TypeDBTransaction; +import com.vaticle.typedb.driver.common.exception.TypeDBDriverException; import com.vaticle.typedb.osi.loader.config.Configuration; import com.vaticle.typedb.osi.loader.io.FileLogger; import com.vaticle.typedb.osi.loader.util.GeneratorUtil; @@ -63,7 +63,7 @@ public void write(TypeDBTransaction tx, String[] row, boolean allowMultiInsert) if (isValid(statement)) { try { tx.query().insert(statement); - } catch (TypeDBClientException clientException) { + } catch (TypeDBDriverException driverException) { FileLogger.getLogger().logUnavailable(fileName, originalRow); dataLogger.error("TypeDB Unavailable - Row in <" + filePath + "> not inserted - written to <" + fileNoExtension + "_unavailable.log" + ">"); } diff --git a/src/main/java/com/vaticle/typedb/osi/loader/generator/EntityGenerator.java b/src/main/java/com/vaticle/typedb/osi/loader/generator/EntityGenerator.java index 0642182..1f9be52 100644 --- a/src/main/java/com/vaticle/typedb/osi/loader/generator/EntityGenerator.java +++ b/src/main/java/com/vaticle/typedb/osi/loader/generator/EntityGenerator.java @@ -16,15 +16,15 @@ package com.vaticle.typedb.osi.loader.generator; -import com.vaticle.typedb.client.api.TypeDBTransaction; -import com.vaticle.typedb.client.common.exception.TypeDBClientException; +import com.vaticle.typedb.driver.api.TypeDBTransaction; +import com.vaticle.typedb.driver.common.exception.TypeDBDriverException; import com.vaticle.typedb.osi.loader.config.Configuration; import com.vaticle.typedb.osi.loader.io.FileLogger; import com.vaticle.typedb.osi.loader.util.GeneratorUtil; import com.vaticle.typedb.osi.loader.util.TypeDBUtil; import com.vaticle.typedb.osi.loader.util.Util; import com.vaticle.typeql.lang.TypeQL; -import com.vaticle.typeql.lang.pattern.variable.ThingVariable; +import com.vaticle.typeql.lang.pattern.statement.ThingStatement; import com.vaticle.typeql.lang.query.TypeQLInsert; import org.apache.commons.io.FilenameUtils; import org.apache.logging.log4j.LogManager; @@ -61,7 +61,7 @@ public void write(TypeDBTransaction tx, String[] row, boolean allowMultiInsert) if (valid(query)) { try { tx.query().insert(query); - } catch (TypeDBClientException typeDBClientException) { + } catch (TypeDBDriverException typeDBDriverException) { FileLogger.getLogger().logUnavailable(fileName, originalRow); dataLogger.error("TypeDB Unavailable - Row in <" + filePath + "> not inserted - written to <" + fileNoExtension + "_unavailable.log" + ">"); } @@ -73,7 +73,7 @@ public void write(TypeDBTransaction tx, String[] row, boolean allowMultiInsert) public TypeQLInsert generateThingInsertStatement(String[] row) { if (row.length > 0) { - ThingVariable.Thing insertStatement = GeneratorUtil.generateBoundThingVar(entityConfiguration.getInsert().getEntity()); + ThingStatement insertStatement = GeneratorUtil.generateBoundThingVar(entityConfiguration.getInsert().getEntity()); GeneratorUtil.constrainThingWithHasAttributes(row, header, filePath, fileSeparator, insertStatement, entityConfiguration.getInsert().getOwnerships()); diff --git a/src/main/java/com/vaticle/typedb/osi/loader/generator/Generator.java b/src/main/java/com/vaticle/typedb/osi/loader/generator/Generator.java index b8ae391..cc279c2 100644 --- a/src/main/java/com/vaticle/typedb/osi/loader/generator/Generator.java +++ b/src/main/java/com/vaticle/typedb/osi/loader/generator/Generator.java @@ -16,7 +16,7 @@ package com.vaticle.typedb.osi.loader.generator; -import com.vaticle.typedb.client.api.TypeDBTransaction; +import com.vaticle.typedb.driver.api.TypeDBTransaction; public interface Generator { void write(TypeDBTransaction tx, String[] row, boolean allowMultiInsert); diff --git a/src/main/java/com/vaticle/typedb/osi/loader/generator/RelationGenerator.java b/src/main/java/com/vaticle/typedb/osi/loader/generator/RelationGenerator.java index 1492900..9861b7d 100644 --- a/src/main/java/com/vaticle/typedb/osi/loader/generator/RelationGenerator.java +++ b/src/main/java/com/vaticle/typedb/osi/loader/generator/RelationGenerator.java @@ -16,18 +16,18 @@ package com.vaticle.typedb.osi.loader.generator; -import com.vaticle.typedb.client.api.TypeDBTransaction; -import com.vaticle.typedb.client.api.answer.ConceptMap; -import com.vaticle.typedb.client.common.exception.TypeDBClientException; +import com.vaticle.typedb.driver.api.TypeDBTransaction; +import com.vaticle.typedb.driver.api.answer.ConceptMap; +import com.vaticle.typedb.driver.common.exception.TypeDBDriverException; import com.vaticle.typedb.osi.loader.config.Configuration; import com.vaticle.typedb.osi.loader.io.FileLogger; import com.vaticle.typedb.osi.loader.util.GeneratorUtil; import com.vaticle.typedb.osi.loader.util.TypeDBUtil; import com.vaticle.typedb.osi.loader.util.Util; import com.vaticle.typeql.lang.TypeQL; +import com.vaticle.typeql.lang.builder.ConceptVariableBuilder; import com.vaticle.typeql.lang.pattern.constraint.ThingConstraint; -import com.vaticle.typeql.lang.pattern.variable.ThingVariable; -import com.vaticle.typeql.lang.pattern.variable.UnboundConceptVariable; +import com.vaticle.typeql.lang.pattern.statement.ThingStatement; import com.vaticle.typeql.lang.query.TypeQLInsert; import org.apache.commons.io.FilenameUtils; import org.apache.logging.log4j.LogManager; @@ -76,7 +76,7 @@ public void write(TypeDBTransaction tx, String[] row, boolean allowMultiInsert) } else { safeInsert(tx, query, answers, allowMultiInsert, filePath, originalRow, dataLogger); } - } catch (TypeDBClientException typeDBClientException) { + } catch (TypeDBDriverException typeDBDriverException) { FileLogger.getLogger().logUnavailable(fileName, originalRow); dataLogger.error("TypeDB Unavailable - Row in <" + filePath + "> not inserted - written to <" + fileNoExtension + "_unavailable.log" + ">"); } @@ -88,7 +88,7 @@ public void write(TypeDBTransaction tx, String[] row, boolean allowMultiInsert) public TypeQLInsert generateMatchInsertStatement(String[] row) { if (row.length > 0) { - ArrayList> playerMatchStatements = new ArrayList<>(); + ArrayList> playerMatchStatements = new ArrayList<>(); ArrayList playerVars = new ArrayList<>(); ArrayList roleTypes = new ArrayList<>(); @@ -98,7 +98,7 @@ public TypeQLInsert generateMatchInsertStatement(String[] row) { // ATTRIBUTE PLAYER if (Util.playerType(player).equals("attribute")) { - ThingVariable.Attribute playerMatchStatement = getAttributePlayerMatchStatement(row, player, playerVar); + ThingStatement.Attribute playerMatchStatement = getAttributePlayerMatchStatement(row, player, playerVar); if (playerMatchStatement != null) { playerMatchStatements.add(playerMatchStatement); playerVars.add(playerVar); @@ -109,7 +109,7 @@ public TypeQLInsert generateMatchInsertStatement(String[] row) { // ENTITY & RELATION PLAYER BY ATTRIBUTE(s) if (Util.playerType(player).equals("byAttribute")) { - ThingVariable.Thing playerMatchStatement = getThingPlayerMatchStatementByAttribute(row, player, playerVar); + ThingStatement.Thing playerMatchStatement = getThingPlayerMatchStatementByAttribute(row, player, playerVar); if (playerMatchStatement.constraints().stream().anyMatch(ThingConstraint::isHas)) { playerMatchStatements.add(playerMatchStatement); playerVars.add(playerVar); @@ -120,7 +120,7 @@ public TypeQLInsert generateMatchInsertStatement(String[] row) { // // Relation PLAYER BY PLAYERs if (Util.playerType(player).equals("byPlayer")) { - ArrayList> playerMatchStatement = getRelationPlayerMatchStatement(row, player, playerVar); + ArrayList> playerMatchStatement = getRelationPlayerMatchStatement(row, player, playerVar); playerMatchStatements.addAll(playerMatchStatement); playerVars.add(playerVar); roleTypes.add(player.getRole()); @@ -129,7 +129,7 @@ public TypeQLInsert generateMatchInsertStatement(String[] row) { } - ThingVariable.Relation insertStatement = null; + ThingStatement.Relation insertStatement = null; for (int i = 0; i < roleTypes.size(); i++) { if (insertStatement == null) { insertStatement = TypeQL.cVar("rel").rel(roleTypes.get(i), TypeQL.cVar(playerVars.get(i))); @@ -152,8 +152,8 @@ public TypeQLInsert generateMatchInsertStatement(String[] row) { } } - private ThingVariable.Thing getThingPlayerMatchStatementByAttribute(String[] row, Configuration.Definition.Player player, String playerVar) { - ThingVariable.Thing playerMatchStatement = TypeQL.cVar(playerVar).isa(player.getMatch().getType()); + private ThingStatement.Thing getThingPlayerMatchStatementByAttribute(String[] row, Configuration.Definition.Player player, String playerVar) { + ThingStatement.Thing playerMatchStatement = TypeQL.cVar(playerVar).isa(player.getMatch().getType()); for (Configuration.Definition.Attribute consA : player.getMatch().getOwnerships()) { ArrayList constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute( row, header, filePath, fileSeparator, consA); @@ -164,7 +164,7 @@ private ThingVariable.Thing getThingPlayerMatchStatementByAttribute(String[] row return playerMatchStatement; } - private ThingVariable.Attribute getAttributePlayerMatchStatement(String[] row, Configuration.Definition.Player player, String playerVar) { + private ThingStatement.Attribute getAttributePlayerMatchStatement(String[] row, Configuration.Definition.Player player, String playerVar) { ArrayList constraints = GeneratorUtil.generateValueConstraintsConstrainingAttribute( row, header, filePath, fileSeparator, player.getMatch().getAttribute()); if (constraints.size() > 0) { @@ -176,35 +176,35 @@ private ThingVariable.Attribute getAttributePlayerMatchStatement(String[] row, C } } - private ArrayList> getRelationPlayerMatchStatement(String[] row, Configuration.Definition.Player player, String playerVar) { + private ArrayList> getRelationPlayerMatchStatement(String[] row, Configuration.Definition.Player player, String playerVar) { return recursiveAssemblyMatchStatement(row, player, playerVar); } - private ArrayList> recursiveAssemblyMatchStatement(String[] row, + private ArrayList> recursiveAssemblyMatchStatement(String[] row, Configuration.Definition.Player player, String playerVar) { if (Util.playerType(player).equals("attribute")) { //terminating condition - attribute player: - ArrayList> statements = new ArrayList<>(); - ThingVariable statement = getAttributePlayerMatchStatement(row, player, playerVar); + ArrayList> statements = new ArrayList<>(); + ThingStatement statement = getAttributePlayerMatchStatement(row, player, playerVar); if (statement != null) { statements.add(statement); } return statements; } else if (Util.playerType(player).equals("byAttribute")) { //terminating condition - byAttribute player: - ArrayList> statements = new ArrayList<>(); - ThingVariable statement = getThingPlayerMatchStatementByAttribute(row, player, playerVar); + ArrayList> statements = new ArrayList<>(); + ThingStatement statement = getThingPlayerMatchStatementByAttribute(row, player, playerVar); if (statement != null && statement.constraints().stream().anyMatch(ThingConstraint::isHas)) { statements.add(statement); } return statements; } else if (Util.playerType(player).equals("byPlayer")) { // identify relation player "byPlayer" - ArrayList> statements = new ArrayList<>(); + ArrayList> statements = new ArrayList<>(); //create the relation statement with the player vars that will be filled in recursion: - UnboundConceptVariable ubv = TypeQL.cVar(playerVar); - ThingVariable.Relation relationMatch = null; + ConceptVariableBuilder ubv = TypeQL.cVar(playerVar); + ThingStatement.Relation relationMatch = null; for (int idx = 0; idx < player.getMatch().getPlayers().length; idx++) { Configuration.Definition.Player curPlayer = player.getMatch().getPlayers()[idx]; String curPlayerVar = playerVar + "-" + idx; @@ -214,7 +214,7 @@ private ArrayList> recursiveAssemblyMatchStatement(String[] row relationMatch = relationMatch.rel(curPlayer.getRole(), TypeQL.cVar(curPlayerVar)); } // this is where the recursion happens to fill the player var! - ArrayList> recursiveMatch = recursiveAssemblyMatchStatement(row, curPlayer, curPlayerVar); + ArrayList> recursiveMatch = recursiveAssemblyMatchStatement(row, curPlayer, curPlayerVar); // now add whatever the recursion brought back: statements.addAll(recursiveMatch); } diff --git a/src/main/java/com/vaticle/typedb/osi/loader/loader/AsyncLoaderWorker.java b/src/main/java/com/vaticle/typedb/osi/loader/loader/AsyncLoaderWorker.java index 6c9265e..b367aca 100644 --- a/src/main/java/com/vaticle/typedb/osi/loader/loader/AsyncLoaderWorker.java +++ b/src/main/java/com/vaticle/typedb/osi/loader/loader/AsyncLoaderWorker.java @@ -16,9 +16,9 @@ package com.vaticle.typedb.osi.loader.loader; -import com.vaticle.typedb.client.api.TypeDBClient; -import com.vaticle.typedb.client.api.TypeDBSession; -import com.vaticle.typedb.client.api.TypeDBTransaction; +import com.vaticle.typedb.driver.api.TypeDBDriver; +import com.vaticle.typedb.driver.api.TypeDBSession; +import com.vaticle.typedb.driver.api.TypeDBTransaction; import com.vaticle.typedb.common.collection.Either; import com.vaticle.typedb.common.concurrent.NamedThreadFactory; import com.vaticle.typedb.osi.loader.cli.LoadOptions; @@ -75,7 +75,7 @@ public AsyncLoaderWorker(Configuration dc, LoadOptions loadOptions) { this.status = Status.OK; } - public void run(TypeDBClient client) throws IOException, InterruptedException { + public void run(TypeDBDriver driver) throws IOException, InterruptedException { ArrayList orderedBeforeGenerators = dc.getGlobalConfig().getOrderedBeforeGenerators(); if (orderedBeforeGenerators == null) orderedBeforeGenerators = new ArrayList<>(); @@ -91,7 +91,7 @@ public void run(TypeDBClient client) throws IOException, InterruptedException { separateGenerators.addAll(orderedAfterGenerators); separateGenerators.addAll(ignoreGenerators); - try (TypeDBSession session = TypeDBUtil.getDataSession(client, databaseName)) { + try (TypeDBSession session = TypeDBUtil.getDataSession(driver, databaseName)) { //Load OrderBefore things... Util.info("loading ordered before things"); diff --git a/src/main/java/com/vaticle/typedb/osi/loader/loader/TypeDBLoader.java b/src/main/java/com/vaticle/typedb/osi/loader/loader/TypeDBLoader.java index ea39760..6cd9237 100644 --- a/src/main/java/com/vaticle/typedb/osi/loader/loader/TypeDBLoader.java +++ b/src/main/java/com/vaticle/typedb/osi/loader/loader/TypeDBLoader.java @@ -16,9 +16,9 @@ package com.vaticle.typedb.osi.loader.loader; -import com.vaticle.typedb.client.TypeDB; -import com.vaticle.typedb.client.api.TypeDBClient; -import com.vaticle.typedb.client.api.TypeDBSession; +import com.vaticle.typedb.driver.TypeDB; +import com.vaticle.typedb.driver.api.TypeDBDriver; +import com.vaticle.typedb.driver.api.TypeDBSession; import com.vaticle.typedb.common.concurrent.NamedThreadFactory; import com.vaticle.typedb.osi.loader.cli.LoadOptions; import com.vaticle.typedb.osi.loader.config.Configuration; @@ -42,7 +42,7 @@ public TypeDBLoader(LoadOptions options) { public void load() { Util.info("validating your config..."); - TypeDBClient schemaClient = TypeDBUtil.getClient(options); + TypeDBDriver schemaDriver = TypeDBUtil.getDriver(options); ConfigurationValidation cv = new ConfigurationValidation(dc); HashMap> validationReport = new HashMap<>(); ArrayList errors = new ArrayList<>(); @@ -53,10 +53,10 @@ public void load() { if (validationReport.get("errors").size() == 0) { if (options.cleanMigration) { - TypeDBUtil.cleanAndDefineSchemaToDatabase(schemaClient, options.databaseName, dc.getGlobalConfig().getSchema()); + TypeDBUtil.cleanAndDefineSchemaToDatabase(schemaDriver, options.databaseName, dc.getGlobalConfig().getSchema()); Util.info("cleaned database and migrated schema..."); } else if (options.loadSchema) { - TypeDBUtil.loadAndDefineSchema(schemaClient, options.databaseName, dc.getGlobalConfig().getSchema()); + TypeDBUtil.loadAndDefineSchema(schemaDriver, options.databaseName, dc.getGlobalConfig().getSchema()); Util.info("loaded schema..."); } } else { @@ -64,7 +64,7 @@ public void load() { System.exit(1); } - TypeDBSession schemaSession = TypeDBUtil.getSchemaSession(schemaClient, options.databaseName); + TypeDBSession schemaSession = TypeDBUtil.getSchemaSession(schemaDriver, options.databaseName); cv.validateConfiguration(validationReport, schemaSession); if (validationReport.get("warnings").size() > 0) { @@ -73,22 +73,22 @@ public void load() { if (validationReport.get("errors").size() > 0) { validationReport.get("errors").forEach(Util::error); schemaSession.close(); - schemaClient.close(); + schemaDriver.close(); System.exit(1); } schemaSession.close(); - schemaClient.close(); + schemaDriver.close(); Util.info("finished validating your config..."); Instant start = Instant.now(); try { AsyncLoaderWorker asyncLoaderWorker = null; - try (TypeDBClient client = TypeDBUtil.getClient(options)) { + try (TypeDBDriver driver = TypeDBUtil.getDriver(options)) { Runtime.getRuntime().addShutdownHook( - NamedThreadFactory.create(AsyncLoaderWorker.class, "shutdown").newThread(client::close) + NamedThreadFactory.create(AsyncLoaderWorker.class, "shutdown").newThread(driver::close) ); asyncLoaderWorker = new AsyncLoaderWorker(dc, options); - asyncLoaderWorker.run(client); + asyncLoaderWorker.run(driver); } finally { if (asyncLoaderWorker != null) asyncLoaderWorker.close(); } diff --git a/src/main/java/com/vaticle/typedb/osi/loader/util/GeneratorUtil.java b/src/main/java/com/vaticle/typedb/osi/loader/util/GeneratorUtil.java index 0700eaa..c80d51c 100644 --- a/src/main/java/com/vaticle/typedb/osi/loader/util/GeneratorUtil.java +++ b/src/main/java/com/vaticle/typedb/osi/loader/util/GeneratorUtil.java @@ -24,7 +24,7 @@ import com.vaticle.typeql.lang.common.TypeQLToken; import com.vaticle.typeql.lang.pattern.constraint.Predicate; import com.vaticle.typeql.lang.pattern.constraint.ThingConstraint; -import com.vaticle.typeql.lang.pattern.variable.ThingVariable; +import com.vaticle.typeql.lang.pattern.statement.ThingStatement; import org.apache.commons.io.FilenameUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -53,7 +53,7 @@ public static void constrainThingWithHasAttributes(String[] row, String[] header, String filePath, char fileSeparator, - ThingVariable insertStatement, + ThingStatement insertStatement, Configuration.Definition.Attribute[] attributes) { for (Configuration.Definition.Attribute attribute : attributes) { ArrayList constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute( @@ -68,7 +68,7 @@ public static int getColumnIndexByName(String[] header, String column) { return Arrays.asList(header).indexOf(column); } - public static ThingVariable.Thing generateBoundThingVar(String schemaType) { + public static ThingStatement.Thing generateBoundThingVar(String schemaType) { return TypeQL.cVar("e").isa(schemaType); } diff --git a/src/main/java/com/vaticle/typedb/osi/loader/util/TypeDBUtil.java b/src/main/java/com/vaticle/typedb/osi/loader/util/TypeDBUtil.java index aeccd9d..6eb6d51 100644 --- a/src/main/java/com/vaticle/typedb/osi/loader/util/TypeDBUtil.java +++ b/src/main/java/com/vaticle/typedb/osi/loader/util/TypeDBUtil.java @@ -16,17 +16,18 @@ package com.vaticle.typedb.osi.loader.util; -import com.vaticle.typedb.client.TypeDB; -import com.vaticle.typedb.client.api.TypeDBClient; -import com.vaticle.typedb.client.api.TypeDBCredential; -import com.vaticle.typedb.client.api.TypeDBSession; -import com.vaticle.typedb.client.api.TypeDBTransaction; -import com.vaticle.typedb.client.api.answer.ConceptMap; +import com.vaticle.typedb.driver.TypeDB; +import com.vaticle.typedb.driver.api.TypeDBDriver; +import com.vaticle.typedb.driver.api.TypeDBCredential; +import com.vaticle.typedb.driver.api.TypeDBSession; +import com.vaticle.typedb.driver.api.TypeDBTransaction; +import com.vaticle.typedb.driver.api.answer.ConceptMap; +import com.vaticle.typedb.driver.api.concept.Concept; import com.vaticle.typedb.osi.loader.cli.LoadOptions; import com.vaticle.typedb.osi.loader.io.FileLogger; import com.vaticle.typeql.lang.TypeQL; -import com.vaticle.typeql.lang.pattern.variable.BoundVariable; -import com.vaticle.typeql.lang.pattern.variable.ThingVariable; +import com.vaticle.typeql.lang.pattern.statement.Statement; +import com.vaticle.typeql.lang.pattern.statement.ThingStatement; import com.vaticle.typeql.lang.query.TypeQLDefine; import com.vaticle.typeql.lang.query.TypeQLInsert; import org.apache.commons.io.FilenameUtils; @@ -41,7 +42,7 @@ public class TypeDBUtil { - public static TypeDBClient getClient(LoadOptions options) { + public static TypeDBDriver getDriver(LoadOptions options) { if (options.typedbClusterURI != null) { TypeDBCredential credential; if (options.tlsEnabled) { @@ -51,46 +52,42 @@ public static TypeDBClient getClient(LoadOptions options) { } else { credential = new TypeDBCredential(options.username, options.password, false); } - return TypeDB.clusterClient(options.typedbClusterURI, credential); + return TypeDB.enterpriseDriver(options.typedbClusterURI, credential); } else { - return TypeDB.coreClient(options.typedbURI); + return TypeDB.coreDriver(options.typedbURI); } } - public static TypeDBClient getCoreClient(String typedbURI) { - return TypeDB.coreClient(typedbURI); + public static TypeDBDriver getCoreDriver(String typedbURI) { + return TypeDB.coreDriver(typedbURI); } - public static TypeDBClient getCoreClient(String typedbURI, int parallelization) { - return TypeDB.coreClient(typedbURI, parallelization); + public static TypeDBSession getDataSession(TypeDBDriver driver, String databaseName) { + return driver.session(databaseName, TypeDBSession.Type.DATA); } - public static TypeDBSession getDataSession(TypeDBClient client, String databaseName) { - return client.session(databaseName, TypeDBSession.Type.DATA); + public static TypeDBSession getSchemaSession(TypeDBDriver driver, String databaseName) { + return driver.session(databaseName, TypeDBSession.Type.SCHEMA); } - public static TypeDBSession getSchemaSession(TypeDBClient client, String databaseName) { - return client.session(databaseName, TypeDBSession.Type.SCHEMA); + private static void createDatabase(TypeDBDriver driver, String databaseName) { + driver.databases().create(databaseName); } - private static void createDatabase(TypeDBClient client, String databaseName) { - client.databases().create(databaseName); - } - - private static void deleteDatabaseIfExists(TypeDBClient client, String databaseName) { - if (client.databases().contains(databaseName)) { - client.databases().get(databaseName).delete(); + private static void deleteDatabaseIfExists(TypeDBDriver driver, String databaseName) { + if (driver.databases().contains(databaseName)) { + driver.databases().get(databaseName).delete(); } } - public static void cleanAndDefineSchemaToDatabase(TypeDBClient client, String databaseName, String schemaPath) { - deleteDatabaseIfExists(client, databaseName); - createDatabase(client, databaseName); - loadAndDefineSchema(client, databaseName, schemaPath); + public static void cleanAndDefineSchemaToDatabase(TypeDBDriver driver, String databaseName, String schemaPath) { + deleteDatabaseIfExists(driver, databaseName); + createDatabase(driver, databaseName); + loadAndDefineSchema(driver, databaseName, schemaPath); } - private static void defineToTypeDB(TypeDBClient client, String databaseName, String schemaAsString) { - TypeDBSession schemaSession = getSchemaSession(client, databaseName); + private static void defineToTypeDB(TypeDBDriver driver, String databaseName, String schemaAsString) { + TypeDBSession schemaSession = getSchemaSession(driver, databaseName); TypeQLDefine q = TypeQL.parseQuery(schemaAsString); try (TypeDBTransaction writeTransaction = schemaSession.transaction(TypeDBTransaction.Type.WRITE)) { @@ -103,14 +100,14 @@ private static void defineToTypeDB(TypeDBClient client, String databaseName, Str Util.info("Defined schema to database <" + databaseName + ">"); } - public static void loadAndDefineSchema(TypeDBClient client, String databaseName, String schemaPath) { + public static void loadAndDefineSchema(TypeDBDriver driver, String databaseName, String schemaPath) { String schema = loadSchemaFromFile(schemaPath); - defineToTypeDB(client, databaseName, schema); + defineToTypeDB(driver, databaseName, schema); } public static Iterator executeMatch(TypeDBTransaction tx, TypeQLInsert query) { if (!query.match().isPresent()) throw new RuntimeException("Expected TypeQL 'match' to be present"); - return tx.query().match(query.match().get()).iterator(); + return tx.query().get(query.match().get().get()).iterator(); } public static void safeInsert(TypeDBTransaction tx, TypeQLInsert query, Iterator matches, boolean allowMultiInsert, String filePath, String row, Logger dataLogger) { @@ -131,9 +128,10 @@ public static void safeInsert(TypeDBTransaction tx, TypeQLInsert query, Iterator public static TypeQLInsert replaceMatchWithAnswer(TypeQLInsert query, ConceptMap ans) { assert query.match().isPresent(); - List> insertVars = query.asInsert().variables(); - List matchVars = new ArrayList<>(); - ans.map().forEach((var, concept) -> { + List> insertVars = query.asInsert().statements(); + List matchVars = new ArrayList<>(); + ans.variables().forEach((var) -> { + Concept concept = ans.get(var); if (concept.isThing()) matchVars.add(TypeQL.cVar(var).iid(concept.asThing().getIID())); else if (concept.asType().getLabel().scope().isPresent()) { matchVars.add(TypeQL.cVar(var).type(concept.asType().getLabel().scope().get(), concept.asType().getLabel().name())); diff --git a/src/main/java/com/vaticle/typedb/osi/loader/util/Util.java b/src/main/java/com/vaticle/typedb/osi/loader/util/Util.java index ae53fca..4009e14 100644 --- a/src/main/java/com/vaticle/typedb/osi/loader/util/Util.java +++ b/src/main/java/com/vaticle/typedb/osi/loader/util/Util.java @@ -16,9 +16,9 @@ package com.vaticle.typedb.osi.loader.util; -import com.google.common.reflect.TypeToken; import com.google.gson.Gson; -import com.vaticle.typedb.client.api.TypeDBSession; +import com.google.gson.reflect.TypeToken; +import com.vaticle.typedb.driver.api.TypeDBSession; import com.vaticle.typedb.osi.loader.config.Configuration; import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVParser; diff --git a/src/test/java/com/vaticle/typedb/osi/loader/cli/TypeDBLoaderCLITest.java b/src/test/java/com/vaticle/typedb/osi/loader/cli/TypeDBLoaderCLITest.java index 811a8ad..8bc5001 100644 --- a/src/test/java/com/vaticle/typedb/osi/loader/cli/TypeDBLoaderCLITest.java +++ b/src/test/java/com/vaticle/typedb/osi/loader/cli/TypeDBLoaderCLITest.java @@ -16,9 +16,9 @@ package com.vaticle.typedb.osi.loader.cli; -import com.vaticle.typedb.client.api.TypeDBClient; -import com.vaticle.typedb.client.api.TypeDBSession; -import com.vaticle.typedb.client.api.TypeDBTransaction; +import com.vaticle.typedb.driver.api.TypeDBDriver; +import com.vaticle.typedb.driver.api.TypeDBSession; +import com.vaticle.typedb.driver.api.TypeDBTransaction; import com.vaticle.typedb.osi.loader.loader.TypeDBLoader; import com.vaticle.typedb.osi.loader.util.TypeDBUtil; import com.vaticle.typeql.lang.TypeQL; @@ -115,13 +115,13 @@ public void migrateTestContinue() { private void clearData(String uri, String db) { System.out.println("Cleaning all previous loaded data in: " + db); - TypeDBClient client = TypeDBUtil.getCoreClient(uri); - try (TypeDBSession session = TypeDBUtil.getDataSession(client, db)) { + TypeDBDriver driver = TypeDBUtil.getCoreDriver(uri); + try (TypeDBSession session = TypeDBUtil.getDataSession(driver, db)) { try (TypeDBTransaction txn = session.transaction(TypeDBTransaction.Type.WRITE)) { txn.query().delete(TypeQL.parseQuery("match $x isa thing; delete $x isa thing;").asDelete()); txn.commit(); } } - client.close(); + driver.close(); } } diff --git a/src/test/java/com/vaticle/typedb/osi/loader/config/ConfigurationValidationTest.java b/src/test/java/com/vaticle/typedb/osi/loader/config/ConfigurationValidationTest.java index 8ea08fd..4b9aba7 100644 --- a/src/test/java/com/vaticle/typedb/osi/loader/config/ConfigurationValidationTest.java +++ b/src/test/java/com/vaticle/typedb/osi/loader/config/ConfigurationValidationTest.java @@ -17,8 +17,8 @@ package com.vaticle.typedb.osi.loader.config; -import com.vaticle.typedb.client.api.TypeDBClient; -import com.vaticle.typedb.client.api.TypeDBSession; +import com.vaticle.typedb.driver.api.TypeDBDriver; +import com.vaticle.typedb.driver.api.TypeDBSession; import com.vaticle.typedb.osi.loader.util.TypeDBUtil; import com.vaticle.typedb.osi.loader.util.Util; import org.apache.logging.log4j.LogManager; @@ -86,7 +86,7 @@ public void validateErrorDataConfig() { Configuration dc = Util.initializeConfig(new File("src/test/resources/generic/configValidationTest.json").getAbsolutePath()); assert dc != null; - TypeDBClient schemaClient = TypeDBUtil.getCoreClient(typedbURI, Runtime.getRuntime().availableProcessors()); + TypeDBDriver schemaDriver = TypeDBUtil.getCoreDriver(typedbURI); ConfigurationValidation cv = new ConfigurationValidation(dc); @@ -98,13 +98,13 @@ public void validateErrorDataConfig() { cv.validateSchemaPresent(validationReport); if (validationReport.get("errors").size() == 0) { - TypeDBUtil.cleanAndDefineSchemaToDatabase(schemaClient, databaseName, dc.getGlobalConfig().getSchema()); + TypeDBUtil.cleanAndDefineSchemaToDatabase(schemaDriver, databaseName, dc.getGlobalConfig().getSchema()); appLogger.info("cleaned database and migrated schema..."); } - TypeDBSession schemaSession = TypeDBUtil.getSchemaSession(schemaClient, databaseName); + TypeDBSession schemaSession = TypeDBUtil.getSchemaSession(schemaDriver, databaseName); cv.validateConfiguration(validationReport, schemaSession); schemaSession.close(); - schemaClient.close(); + schemaDriver.close(); validationReport.get("warnings").forEach(appLogger::warn); validationReport.get("errors").forEach(appLogger::error); @@ -118,7 +118,7 @@ public void validateErrorDataConfigPhoneCalls() { Configuration dc = Util.initializeConfig(new File("src/test/resources/phoneCalls/configValidationTest.json").getAbsolutePath()); assert dc != null; - TypeDBClient schemaClient = TypeDBUtil.getCoreClient(typedbURI, Runtime.getRuntime().availableProcessors()); + TypeDBDriver schemaDriver = TypeDBUtil.getCoreDriver(typedbURI); ConfigurationValidation cv = new ConfigurationValidation(dc); @@ -130,13 +130,13 @@ public void validateErrorDataConfigPhoneCalls() { cv.validateSchemaPresent(validationReport); if (validationReport.get("errors").size() == 0) { - TypeDBUtil.cleanAndDefineSchemaToDatabase(schemaClient, databaseName, dc.getGlobalConfig().getSchema()); + TypeDBUtil.cleanAndDefineSchemaToDatabase(schemaDriver, databaseName, dc.getGlobalConfig().getSchema()); appLogger.info("cleaned database and migrated schema..."); } - TypeDBSession schemaSession = TypeDBUtil.getSchemaSession(schemaClient, databaseName); + TypeDBSession schemaSession = TypeDBUtil.getSchemaSession(schemaDriver, databaseName); cv.validateConfiguration(validationReport, schemaSession); schemaSession.close(); - schemaClient.close(); + schemaDriver.close(); validationReport.get("warnings").forEach(appLogger::warn); validationReport.get("errors").forEach(appLogger::error); @@ -147,7 +147,7 @@ public void validateErrorDataConfigPhoneCalls() { public void validateDataConfig() { Configuration dc = Util.initializeConfig(new File("src/test/resources/generic/config.json").getAbsolutePath()); assert dc != null; - TypeDBClient schemaClient = TypeDBUtil.getCoreClient(typedbURI, Runtime.getRuntime().availableProcessors()); + TypeDBDriver schemaDriver = TypeDBUtil.getCoreDriver(typedbURI); ConfigurationValidation cv = new ConfigurationValidation(dc); @@ -159,14 +159,14 @@ public void validateDataConfig() { cv.validateSchemaPresent(validationReport); if (validationReport.get("errors").size() == 0) { - TypeDBUtil.cleanAndDefineSchemaToDatabase(schemaClient, databaseName, dc.getGlobalConfig().getSchema()); + TypeDBUtil.cleanAndDefineSchemaToDatabase(schemaDriver, databaseName, dc.getGlobalConfig().getSchema()); appLogger.info("cleaned database and migrated schema..."); } - TypeDBSession schemaSession = TypeDBUtil.getSchemaSession(schemaClient, databaseName); + TypeDBSession schemaSession = TypeDBUtil.getSchemaSession(schemaDriver, databaseName); cv.validateConfiguration(validationReport, schemaSession); schemaSession.close(); - schemaClient.close(); + schemaDriver.close(); validationReport.get("warnings").forEach(appLogger::warn); validationReport.get("errors").forEach(appLogger::error); @@ -179,7 +179,7 @@ public void validatePhoneCallsDataConfig() { Configuration dc = Util.initializeConfig(new File("src/test/resources/phoneCalls/config.json").getAbsolutePath()); assert dc != null; - TypeDBClient schemaClient = TypeDBUtil.getCoreClient(typedbURI, Runtime.getRuntime().availableProcessors()); + TypeDBDriver schemaDriver = TypeDBUtil.getCoreDriver(typedbURI); ConfigurationValidation cv = new ConfigurationValidation(dc); HashMap> validationReport = new HashMap<>(); @@ -189,14 +189,14 @@ public void validatePhoneCallsDataConfig() { validationReport.put("errors", errors); cv.validateSchemaPresent(validationReport); if (validationReport.get("errors").size() == 0) { - TypeDBUtil.cleanAndDefineSchemaToDatabase(schemaClient, databaseName, dc.getGlobalConfig().getSchema()); + TypeDBUtil.cleanAndDefineSchemaToDatabase(schemaDriver, databaseName, dc.getGlobalConfig().getSchema()); appLogger.info("cleaned database and migrated schema..."); } - TypeDBSession schemaSession = TypeDBUtil.getSchemaSession(schemaClient, databaseName); + TypeDBSession schemaSession = TypeDBUtil.getSchemaSession(schemaDriver, databaseName); cv.validateConfiguration(validationReport, schemaSession); schemaSession.close(); - schemaClient.close(); + schemaDriver.close(); validationReport.get("warnings").forEach(appLogger::warn); validationReport.get("errors").forEach(appLogger::error); diff --git a/src/test/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeGeneratorTest.java b/src/test/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeGeneratorTest.java index 701deac..7f553f1 100644 --- a/src/test/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeGeneratorTest.java +++ b/src/test/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeGeneratorTest.java @@ -16,8 +16,8 @@ package com.vaticle.typedb.osi.loader.generator; -import com.vaticle.typedb.client.api.TypeDBClient; -import com.vaticle.typedb.client.api.TypeDBSession; +import com.vaticle.typedb.driver.api.TypeDBDriver; +import com.vaticle.typedb.driver.api.TypeDBSession; import com.vaticle.typedb.osi.loader.config.Configuration; import com.vaticle.typedb.osi.loader.util.TypeDBUtil; import com.vaticle.typedb.osi.loader.util.Util; @@ -39,14 +39,14 @@ public class AppendAttributeGeneratorTest { public void phoneCallsPersonTest() throws IOException { String dbName = "append-attribute-generator-test"; String sp = new File("src/test/resources/phoneCalls/schema.gql").getAbsolutePath(); - TypeDBClient client = TypeDBUtil.getCoreClient("localhost:1729"); - TypeDBUtil.cleanAndDefineSchemaToDatabase(client, dbName, sp); + TypeDBDriver driver = TypeDBUtil.getCoreDriver("localhost:1729"); + TypeDBUtil.cleanAndDefineSchemaToDatabase(driver, dbName, sp); String dcp = new File("src/test/resources/phoneCalls/config.json").getAbsolutePath(); Configuration dc = Util.initializeConfig(dcp); assert dc != null; ArrayList appendKeys = new ArrayList<>(List.of("append-twitter", "append-fakebook", "append-call-rating")); - TypeDBSession session = TypeDBUtil.getDataSession(client, dbName); + TypeDBSession session = TypeDBUtil.getDataSession(driver, dbName); for (String appendkey : appendKeys) { Configuration.Definition.Attribute[] hasAttributes = dc.getAppendAttribute().get(appendkey).getInsert().getOwnerships(); if (hasAttributes != null) { @@ -58,7 +58,7 @@ public void phoneCallsPersonTest() throws IOException { } } session.close(); - client.close(); + driver.close(); testTwitter(dc, appendKeys); testFakebook(dc, appendKeys); diff --git a/src/test/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeOrInsertThingGeneratorTest.java b/src/test/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeOrInsertThingGeneratorTest.java index 1a44b05..ad8010b 100644 --- a/src/test/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeOrInsertThingGeneratorTest.java +++ b/src/test/java/com/vaticle/typedb/osi/loader/generator/AppendAttributeOrInsertThingGeneratorTest.java @@ -17,8 +17,8 @@ package com.vaticle.typedb.osi.loader.generator; -import com.vaticle.typedb.client.api.TypeDBClient; -import com.vaticle.typedb.client.api.TypeDBSession; +import com.vaticle.typedb.driver.api.TypeDBDriver; +import com.vaticle.typedb.driver.api.TypeDBSession; import com.vaticle.typedb.osi.loader.config.Configuration; import com.vaticle.typedb.osi.loader.util.TypeDBUtil; import com.vaticle.typedb.osi.loader.util.Util; @@ -40,14 +40,14 @@ public class AppendAttributeOrInsertThingGeneratorTest { public void phoneCallsPersonTest() throws IOException { String dbName = "append-or-insert-generator-test"; String sp = new File("src/test/resources/phoneCalls/schema.gql").getAbsolutePath(); - TypeDBClient client = TypeDBUtil.getCoreClient("localhost:1729"); - TypeDBUtil.cleanAndDefineSchemaToDatabase(client, dbName, sp); + TypeDBDriver driver = TypeDBUtil.getCoreDriver("localhost:1729"); + TypeDBUtil.cleanAndDefineSchemaToDatabase(driver, dbName, sp); String dcp = new File("src/test/resources/phoneCalls/config.json").getAbsolutePath(); Configuration dc = Util.initializeConfig(dcp); assert dc != null; ArrayList appendOrInsertKeys = new ArrayList<>(List.of("append-or-insert-person")); - TypeDBSession session = TypeDBUtil.getDataSession(client, dbName); + TypeDBSession session = TypeDBUtil.getDataSession(driver, dbName); for (String appendOrInsertkey : appendOrInsertKeys) { if (dc.getAppendAttributeOrInsertThing().get(appendOrInsertkey).getInsert().getOwnerships() != null) { Util.setConstrainingAttributeConceptType(dc.getAppendAttributeOrInsertThing().get(appendOrInsertkey).getInsert().getOwnerships(), session); @@ -57,7 +57,7 @@ public void phoneCallsPersonTest() throws IOException { } } session.close(); - client.close(); + driver.close(); testPerson(dc, appendOrInsertKeys); } diff --git a/src/test/java/com/vaticle/typedb/osi/loader/generator/AttributeGeneratorTest.java b/src/test/java/com/vaticle/typedb/osi/loader/generator/AttributeGeneratorTest.java index 51caf91..3f1499c 100644 --- a/src/test/java/com/vaticle/typedb/osi/loader/generator/AttributeGeneratorTest.java +++ b/src/test/java/com/vaticle/typedb/osi/loader/generator/AttributeGeneratorTest.java @@ -16,8 +16,8 @@ package com.vaticle.typedb.osi.loader.generator; -import com.vaticle.typedb.client.api.TypeDBClient; -import com.vaticle.typedb.client.api.TypeDBSession; +import com.vaticle.typedb.driver.api.TypeDBDriver; +import com.vaticle.typedb.driver.api.TypeDBSession; import com.vaticle.typedb.osi.loader.config.Configuration; import com.vaticle.typedb.osi.loader.util.TypeDBUtil; import com.vaticle.typedb.osi.loader.util.Util; @@ -38,8 +38,8 @@ public class AttributeGeneratorTest { public void generateInsertStatementsTest() throws IOException { String dbName = "attribute-generator-test"; String sp = new File("src/test/resources/phoneCalls/schema.gql").getAbsolutePath(); - TypeDBClient client = TypeDBUtil.getCoreClient("localhost:1729"); - TypeDBUtil.cleanAndDefineSchemaToDatabase(client, dbName, sp); + TypeDBDriver driver = TypeDBUtil.getCoreDriver("localhost:1729"); + TypeDBUtil.cleanAndDefineSchemaToDatabase(driver, dbName, sp); String dp = new File("src/test/resources/phoneCalls/is-in-use.csv").getAbsolutePath(); String dcp = new File("src/test/resources/phoneCalls/config.json").getAbsolutePath(); @@ -50,10 +50,10 @@ public void generateInsertStatementsTest() throws IOException { dc.getAttributes().get(attributeKey), Objects.requireNonNullElseGet(dc.getAttributes().get(attributeKey).getConfig().getSeparator(), () -> dc.getGlobalConfig().getSeparator())); - TypeDBSession session = TypeDBUtil.getDataSession(client, dbName); + TypeDBSession session = TypeDBUtil.getDataSession(driver, dbName); dc.getAttributes().get(attributeKey).getInsert().setConceptValueType(session); session.close(); - client.close(); + driver.close(); Iterator iterator = Util.newBufferedReader(dp).lines().skip(1).iterator(); diff --git a/src/test/java/com/vaticle/typedb/osi/loader/generator/EntityGeneratorTest.java b/src/test/java/com/vaticle/typedb/osi/loader/generator/EntityGeneratorTest.java index 4bcee7a..83b7771 100644 --- a/src/test/java/com/vaticle/typedb/osi/loader/generator/EntityGeneratorTest.java +++ b/src/test/java/com/vaticle/typedb/osi/loader/generator/EntityGeneratorTest.java @@ -16,8 +16,8 @@ package com.vaticle.typedb.osi.loader.generator; -import com.vaticle.typedb.client.api.TypeDBClient; -import com.vaticle.typedb.client.api.TypeDBSession; +import com.vaticle.typedb.driver.api.TypeDBDriver; +import com.vaticle.typedb.driver.api.TypeDBSession; import com.vaticle.typedb.osi.loader.config.Configuration; import com.vaticle.typedb.osi.loader.util.TypeDBUtil; import com.vaticle.typedb.osi.loader.util.Util; @@ -39,21 +39,21 @@ public class EntityGeneratorTest { public void genericEntityTest() throws IOException { String dbName = "entity-generator-test"; String sp = new File("src/test/resources/generic/schema.gql").getAbsolutePath(); - TypeDBClient client = TypeDBUtil.getCoreClient("localhost:1729"); - TypeDBUtil.cleanAndDefineSchemaToDatabase(client, dbName, sp); + TypeDBDriver driver = TypeDBUtil.getCoreDriver("localhost:1729"); + TypeDBUtil.cleanAndDefineSchemaToDatabase(driver, dbName, sp); String dcp = new File("src/test/resources/generic/config.json").getAbsolutePath(); Configuration dc = Util.initializeConfig(dcp); assert dc != null; ArrayList entityKeys = new ArrayList<>(List.of("entity1", "entity2", "entity3")); - TypeDBSession session = TypeDBUtil.getDataSession(client, dbName); + TypeDBSession session = TypeDBUtil.getDataSession(driver, dbName); for (String entityKey : entityKeys) { for (int idx = 0; idx < dc.getEntities().get(entityKey).getInsert().getOwnerships().length; idx++) { setEntityHasAttributeConceptType(entityKey, idx, dc, session); } } session.close(); - client.close(); + driver.close(); String dp = new File("src/test/resources/generic/entity1.tsv").getAbsolutePath(); EntityGenerator gen = new EntityGenerator(dp, @@ -204,15 +204,15 @@ public void genericEntityTest() throws IOException { public void phoneCallsPersonTest() throws IOException { String dbName = "entity-generator-test"; String sp = new File("src/test/resources/phoneCalls/schema.gql").getAbsolutePath(); - TypeDBClient client = TypeDBUtil.getCoreClient("localhost:1729"); - TypeDBUtil.cleanAndDefineSchemaToDatabase(client, dbName, sp); + TypeDBDriver driver = TypeDBUtil.getCoreDriver("localhost:1729"); + TypeDBUtil.cleanAndDefineSchemaToDatabase(driver, dbName, sp); String dp = new File("src/test/resources/phoneCalls/person.csv").getAbsolutePath(); String dcp = new File("src/test/resources/phoneCalls/config.json").getAbsolutePath(); Configuration dc = Util.initializeConfig(dcp); assert dc != null; String entityKey = "person"; - TypeDBSession session = TypeDBUtil.getDataSession(client, dbName); + TypeDBSession session = TypeDBUtil.getDataSession(driver, dbName); for (int idx = 0; idx < dc.getEntities().get(entityKey).getInsert().getOwnerships().length; idx++) { setEntityHasAttributeConceptType(entityKey, idx, dc, session); } @@ -221,7 +221,7 @@ public void phoneCallsPersonTest() throws IOException { Objects.requireNonNullElseGet(dc.getEntities().get(entityKey).getConfig().getSeparator(), () -> dc.getGlobalConfig().getSeparator())); session.close(); - client.close(); + driver.close(); Iterator iterator = Util.newBufferedReader(dp).lines().skip(1).iterator(); diff --git a/src/test/java/com/vaticle/typedb/osi/loader/generator/RelationGeneratorTest.java b/src/test/java/com/vaticle/typedb/osi/loader/generator/RelationGeneratorTest.java index 6ceb0dd..cd6968a 100644 --- a/src/test/java/com/vaticle/typedb/osi/loader/generator/RelationGeneratorTest.java +++ b/src/test/java/com/vaticle/typedb/osi/loader/generator/RelationGeneratorTest.java @@ -16,8 +16,8 @@ package com.vaticle.typedb.osi.loader.generator; -import com.vaticle.typedb.client.api.TypeDBClient; -import com.vaticle.typedb.client.api.TypeDBSession; +import com.vaticle.typedb.driver.api.TypeDBDriver; +import com.vaticle.typedb.driver.api.TypeDBSession; import com.vaticle.typedb.osi.loader.config.Configuration; import com.vaticle.typedb.osi.loader.util.QueryUtilTest; import com.vaticle.typedb.osi.loader.util.TypeDBUtil; @@ -41,14 +41,14 @@ public void genericRelationTest() throws IOException { String dbName = "relation-generator-test"; String sp = new File("src/test/resources/generic/schema.gql").getAbsolutePath(); - TypeDBClient client = TypeDBUtil.getCoreClient("localhost:1729"); - TypeDBUtil.cleanAndDefineSchemaToDatabase(client, dbName, sp); + TypeDBDriver driver = TypeDBUtil.getCoreDriver("localhost:1729"); + TypeDBUtil.cleanAndDefineSchemaToDatabase(driver, dbName, sp); String dcp = new File("src/test/resources/generic/config.json").getAbsolutePath(); Configuration dc = Util.initializeConfig(dcp); assert dc != null; ArrayList relationKeys = new ArrayList<>(List.of("rel1")); - TypeDBSession session = TypeDBUtil.getDataSession(client, dbName); + TypeDBSession session = TypeDBUtil.getDataSession(driver, dbName); for (String relationKey : relationKeys) { if (dc.getRelations().get(relationKey).getInsert().getOwnerships() != null) { Configuration.Definition.Attribute[] hasAttributes = dc.getRelations().get(relationKey).getInsert().getOwnerships(); @@ -59,7 +59,7 @@ public void genericRelationTest() throws IOException { } } session.close(); - client.close(); + driver.close(); String dp = new File("src/test/resources/generic/rel1.tsv").getAbsolutePath(); RelationGenerator gen = new RelationGenerator(dp, @@ -264,14 +264,14 @@ public void genericRelationTest() throws IOException { public void phoneCallsPersonTest() throws IOException { String dbName = "relation-generator-test"; String sp = new File("src/test/resources/phoneCalls/schema.gql").getAbsolutePath(); - TypeDBClient client = TypeDBUtil.getCoreClient("localhost:1729"); - TypeDBUtil.cleanAndDefineSchemaToDatabase(client, dbName, sp); + TypeDBDriver driver = TypeDBUtil.getCoreDriver("localhost:1729"); + TypeDBUtil.cleanAndDefineSchemaToDatabase(driver, dbName, sp); String dcp = new File("src/test/resources/phoneCalls/config.json").getAbsolutePath(); Configuration dc = Util.initializeConfig(dcp); assert dc != null; ArrayList relationKeys = new ArrayList<>(List.of("contract", "call", "in-use", "communication-channel", "communication-channel-pm")); - TypeDBSession session = TypeDBUtil.getDataSession(client, dbName); + TypeDBSession session = TypeDBUtil.getDataSession(driver, dbName); for (String relationKey : relationKeys) { if (dc.getRelations().get(relationKey).getInsert().getOwnerships() != null) { Configuration.Definition.Attribute[] hasAttributes = dc.getRelations().get(relationKey).getInsert().getOwnerships(); @@ -289,7 +289,7 @@ public void phoneCallsPersonTest() throws IOException { } } session.close(); - client.close(); + driver.close(); testContracts(dc, relationKeys); testCalls(dc, relationKeys); diff --git a/src/test/java/com/vaticle/typedb/osi/loader/loader/TypeDBLoaderTest.java b/src/test/java/com/vaticle/typedb/osi/loader/loader/TypeDBLoaderTest.java index 893b150..fe1b0f0 100644 --- a/src/test/java/com/vaticle/typedb/osi/loader/loader/TypeDBLoaderTest.java +++ b/src/test/java/com/vaticle/typedb/osi/loader/loader/TypeDBLoaderTest.java @@ -16,15 +16,14 @@ package com.vaticle.typedb.osi.loader.loader; -import com.vaticle.typedb.client.api.TypeDBClient; -import com.vaticle.typedb.client.api.TypeDBSession; -import com.vaticle.typedb.client.api.TypeDBTransaction; +import com.vaticle.typedb.driver.api.TypeDBDriver; +import com.vaticle.typedb.driver.api.TypeDBSession; +import com.vaticle.typedb.driver.api.TypeDBTransaction; import com.vaticle.typedb.osi.loader.cli.LoadOptions; import com.vaticle.typedb.osi.loader.util.TypeDBUtil; import com.vaticle.typeql.lang.TypeQL; -import com.vaticle.typeql.lang.pattern.variable.ThingVariable; -import com.vaticle.typeql.lang.pattern.variable.UnboundConceptVariable; -import com.vaticle.typeql.lang.query.TypeQLMatch; +import com.vaticle.typeql.lang.pattern.statement.ThingStatement; +import com.vaticle.typeql.lang.query.TypeQLGet; import org.junit.Assert; import org.junit.Test; @@ -69,8 +68,8 @@ public void loadPhoneCallsTest() { TypeDBLoader typeDBLoader = new TypeDBLoader(LoadOptions.parse(args)); typeDBLoader.load(); - TypeDBClient client = TypeDBUtil.getCoreClient(typeDBUri, 4); - TypeDBSession session = TypeDBUtil.getDataSession(client, databaseName); + TypeDBDriver driver = TypeDBUtil.getCoreDriver(typeDBUri); + TypeDBSession session = TypeDBUtil.getDataSession(driver, databaseName); testAttributes(session); testEntities(session); @@ -81,22 +80,22 @@ public void loadPhoneCallsTest() { testInsertOrAppend(session); session.close(); - client.close(); + driver.close(); } public void testAttributes(TypeDBSession session) { try (TypeDBTransaction read = session.transaction(TypeDBTransaction.Type.READ)) { - TypeQLMatch getQuery = TypeQL.match(TypeQL.cVar("a").isa("is-in-use")).get(TypeQL.cVar("a")); - Assert.assertEquals(3, read.query().match(getQuery).count()); + TypeQLGet getQuery = TypeQL.match(TypeQL.cVar("a").isa("is-in-use")).get(TypeQL.cVar("a")); + Assert.assertEquals(3, read.query().get(getQuery).count()); getQuery = TypeQL.match(TypeQL.cVar("a").eq("yes").isa("is-in-use")).get(TypeQL.cVar("a")); - Assert.assertEquals(1, read.query().match(getQuery).count()); + Assert.assertEquals(1, read.query().get(getQuery).count()); getQuery = TypeQL.match(TypeQL.cVar("a").eq("no").isa("is-in-use")).get(TypeQL.cVar("a")); - Assert.assertEquals(1, read.query().match(getQuery).count()); + Assert.assertEquals(1, read.query().get(getQuery).count()); getQuery = TypeQL.match(TypeQL.cVar("a").eq("5").isa("is-in-use")).get(TypeQL.cVar("a")); - Assert.assertEquals(1, read.query().match(getQuery).count()); + Assert.assertEquals(1, read.query().get(getQuery).count()); } } @@ -104,20 +103,20 @@ public void testEntities(TypeDBSession session) { // query person by phone-number try (TypeDBTransaction read = session.transaction(TypeDBTransaction.Type.READ)) { - TypeQLMatch getQuery = TypeQL.match(TypeQL.cVar("p").isa("person").has("phone-number", "+261 860 539 4754")).get(TypeQL.cVar("p")).limit(1000); - Assert.assertEquals(1, read.query().match(getQuery).count()); + TypeQLGet getQuery = TypeQL.match(TypeQL.cVar("p").isa("person").has("phone-number", "+261 860 539 4754")).get(TypeQL.cVar("p")).limit(1000); + Assert.assertEquals(1, read.query().get(getQuery).count()); // query person by last name getQuery = TypeQL.match(TypeQL.cVar("p").isa("person").has("last-name", "Smith")).get(TypeQL.cVar("p")).limit(1000); - Assert.assertEquals(2, read.query().match(getQuery).count()); + Assert.assertEquals(2, read.query().get(getQuery).count()); // query all entities of type person getQuery = TypeQL.match(TypeQL.cVar("c").isa("person")).get(TypeQL.cVar("c")).limit(1000); - Assert.assertEquals(39, read.query().match(getQuery).count()); + Assert.assertEquals(39, read.query().get(getQuery).count()); // query all entites of type company getQuery = TypeQL.match(TypeQL.cVar("e").isa("company")).get(TypeQL.cVar("e")).limit(1000); - Assert.assertEquals(2, read.query().match(getQuery).count()); + Assert.assertEquals(2, read.query().get(getQuery).count()); } } @@ -125,49 +124,49 @@ public void testRelations(TypeDBSession session) { // query call by duration try (TypeDBTransaction read = session.transaction(TypeDBTransaction.Type.READ)) { - TypeQLMatch getQuery = TypeQL.match(TypeQL.cVar("c").isa("call").has("duration", 2851)).get(TypeQL.cVar("c")).limit(1000); - Assert.assertEquals(1, read.query().match(getQuery).count()); + TypeQLGet getQuery = TypeQL.match(TypeQL.cVar("c").isa("call").has("duration", 2851)).get(TypeQL.cVar("c")).limit(1000); + Assert.assertEquals(1, read.query().get(getQuery).count()); // query call by date getQuery = TypeQL.match(TypeQL.cVar("c").isa("call").has("started-at", getDT("2018-09-17T18:43:42"))).get(TypeQL.cVar("c")).limit(1000); - Assert.assertEquals(1, read.query().match(getQuery).count()); + Assert.assertEquals(1, read.query().get(getQuery).count()); // query call by caller - ThingVariable.Thing player = TypeQL.cVar("p").isa("person").has("phone-number", "+7 171 898 0853"); - ThingVariable.Relation relation = TypeQL.cVar("c").isa("call").toUnbound().rel("caller", TypeQL.cVar("p")); - ArrayList> statements = new ArrayList<>(); + ThingStatement.Thing player = TypeQL.cVar("p").isa("person").has("phone-number", "+7 171 898 0853"); + ThingStatement.Relation relation = TypeQL.cVar("c").rel("caller", TypeQL.cVar("p")).isa("call"); + ArrayList> statements = new ArrayList<>(); statements.add(player); statements.add(relation); getQuery = TypeQL.match(statements).get(TypeQL.cVar("c")).limit(1000); - Assert.assertEquals(14, read.query().match(getQuery).count()); + Assert.assertEquals(14, read.query().get(getQuery).count()); // query call by callee player = TypeQL.cVar("p").isa("person").has("phone-number", "+7 171 898 0853"); - relation = TypeQL.cVar("c").isa("call").toUnbound().rel("callee", TypeQL.cVar("p")); + relation = TypeQL.cVar("c").rel("callee", TypeQL.cVar("p")).isa("call"); statements = new ArrayList<>(); statements.add(player); statements.add(relation); getQuery = TypeQL.match(statements).get(TypeQL.cVar("c")).limit(1000); - Assert.assertEquals(4, read.query().match(getQuery).count()); + Assert.assertEquals(4, read.query().get(getQuery).count()); // query call by caller & callee - ThingVariable.Thing playerOne = TypeQL.cVar("p1").isa("person").has("phone-number", "+7 171 898 0853"); - ThingVariable.Thing playerTwo = TypeQL.cVar("p2").isa("person").has("phone-number", "+57 629 420 5680"); - relation = TypeQL.cVar("c").isa("call").toUnbound().rel("caller", TypeQL.cVar("p1")).rel("callee", TypeQL.cVar("p2")); + ThingStatement.Thing playerOne = TypeQL.cVar("p1").isa("person").has("phone-number", "+7 171 898 0853"); + ThingStatement.Thing playerTwo = TypeQL.cVar("p2").isa("person").has("phone-number", "+57 629 420 5680"); + relation = TypeQL.cVar("c").rel("caller", TypeQL.cVar("p1")).rel("callee", TypeQL.cVar("p2")).isa("call"); statements = new ArrayList<>(); statements.add(playerOne); statements.add(playerTwo); statements.add(relation); getQuery = TypeQL.match(statements).get(TypeQL.cVar("c")).limit(1000); - Assert.assertEquals(4, read.query().match(getQuery).count()); + Assert.assertEquals(4, read.query().get(getQuery).count()); } } public void testAttributeRelation(TypeDBSession session) { TypeDBTransaction read = session.transaction(TypeDBTransaction.Type.READ); - TypeQLMatch getQuery = TypeQL.match(TypeQL.cVar("a").isa("in-use")).get(TypeQL.cVar("a")); - Assert.assertEquals(7, read.query().match(getQuery).count()); + TypeQLGet getQuery = TypeQL.match(TypeQL.cVar("a").isa("in-use")).get(TypeQL.cVar("a")); + Assert.assertEquals(7, read.query().get(getQuery).count()); read.close(); } @@ -176,17 +175,17 @@ public void testNestedRelations(TypeDBSession session) { // query specific communication-channel and count the number of past calls (single past-call): try (TypeDBTransaction read = session.transaction(TypeDBTransaction.Type.READ)) { - ThingVariable.Thing playerOne = TypeQL.cVar("p1").isa("person").has("phone-number", "+54 398 559 0423"); - ThingVariable.Thing playerTwo = TypeQL.cVar("p2").isa("person").has("phone-number", "+48 195 624 2025"); - ThingVariable.Relation relation = TypeQL.cVar("c").rel("peer", TypeQL.cVar("p1")).rel("peer", TypeQL.cVar("p2")).rel("past-call", TypeQL.cVar("x")).isa("communication-channel"); - ArrayList> statements = new ArrayList<>(); + ThingStatement.Thing playerOne = TypeQL.cVar("p1").isa("person").has("phone-number", "+54 398 559 0423"); + ThingStatement.Thing playerTwo = TypeQL.cVar("p2").isa("person").has("phone-number", "+48 195 624 2025"); + ThingStatement.Relation relation = TypeQL.cVar("c").rel("peer", TypeQL.cVar("p1")).rel("peer", TypeQL.cVar("p2")).rel("past-call", TypeQL.cVar("x")).isa("communication-channel"); + ArrayList> statements = new ArrayList<>(); statements.add(playerOne); statements.add(playerTwo); statements.add(relation); - TypeQLMatch getQuery = TypeQL.match(statements).get(TypeQL.cVar("c")).limit(1000); - Assert.assertEquals(1, read.query().match(getQuery).count()); + TypeQLGet getQuery = TypeQL.match(statements).get(TypeQL.cVar("c")).limit(1000); + Assert.assertEquals(1, read.query().get(getQuery).count()); getQuery = TypeQL.match(statements).get(TypeQL.cVar("x")).limit(1000); - Assert.assertEquals(1, read.query().match(getQuery).count()); + Assert.assertEquals(1, read.query().get(getQuery).count()); // query specific communication-channel and count the number of past calls (listSeparated past-calls: playerOne = TypeQL.cVar("p1").isa("person").has("phone-number", "+263 498 495 0617"); @@ -197,9 +196,9 @@ public void testNestedRelations(TypeDBSession session) { statements.add(playerTwo); statements.add(relation); getQuery = TypeQL.match(statements).get(TypeQL.cVar("c")).limit(1000); - Assert.assertEquals(1, read.query().match(getQuery).count()); + Assert.assertEquals(1, read.query().get(getQuery).count()); getQuery = TypeQL.match(statements).get(TypeQL.cVar("x")).limit(1000); - Assert.assertEquals(1, read.query().match(getQuery).count()); + Assert.assertEquals(1, read.query().get(getQuery).count()); // make sure that this doesn't get inserted: playerOne = TypeQL.cVar("p1").isa("person").has("phone-number", "+7 690 597 4443"); @@ -210,9 +209,9 @@ public void testNestedRelations(TypeDBSession session) { statements.add(playerTwo); statements.add(relation); getQuery = TypeQL.match(statements).get(TypeQL.cVar("c")).limit(1000); - Assert.assertEquals(0, read.query().match(getQuery).count()); + Assert.assertEquals(0, read.query().get(getQuery).count()); getQuery = TypeQL.match(statements).get(TypeQL.cVar("x")).limit(1000); - Assert.assertEquals(0, read.query().match(getQuery).count()); + Assert.assertEquals(0, read.query().get(getQuery).count()); // these are added by doing player matching for past calls: playerOne = TypeQL.cVar("p1").isa("person").has("phone-number", "+81 308 988 7153"); @@ -223,9 +222,9 @@ public void testNestedRelations(TypeDBSession session) { statements.add(playerTwo); statements.add(relation); getQuery = TypeQL.match(statements).get(TypeQL.cVar("c")).limit(1000); - Assert.assertEquals(5, read.query().match(getQuery).count()); + Assert.assertEquals(5, read.query().get(getQuery).count()); getQuery = TypeQL.match(statements).get(TypeQL.cVar("x")).limit(1000); - Assert.assertEquals(5, read.query().match(getQuery).count()); + Assert.assertEquals(5, read.query().get(getQuery).count()); playerOne = TypeQL.cVar("p1").isa("person").has("phone-number", "+7 171 898 0853"); playerTwo = TypeQL.cVar("p2").isa("person").has("phone-number", "+57 629 420 5680"); @@ -235,9 +234,9 @@ public void testNestedRelations(TypeDBSession session) { statements.add(playerTwo); statements.add(relation); getQuery = TypeQL.match(statements).get(TypeQL.cVar("c")).limit(1000); - Assert.assertEquals(4, read.query().match(getQuery).count()); + Assert.assertEquals(4, read.query().get(getQuery).count()); getQuery = TypeQL.match(statements).get(TypeQL.cVar("x")).limit(1000); - Assert.assertEquals(4, read.query().match(getQuery).count()); + Assert.assertEquals(4, read.query().get(getQuery).count()); // these must not be found (come from player-matched past-call): playerOne = TypeQL.cVar("p1").isa("person").has("phone-number", "+261 860 539 4754"); @@ -246,9 +245,9 @@ public void testNestedRelations(TypeDBSession session) { statements.add(playerOne); statements.add(relation); getQuery = TypeQL.match(statements).get(TypeQL.cVar("c")).limit(1000); - Assert.assertEquals(0, read.query().match(getQuery).count()); + Assert.assertEquals(0, read.query().get(getQuery).count()); getQuery = TypeQL.match(statements).get(TypeQL.cVar("x")).limit(1000); - Assert.assertEquals(0, read.query().match(getQuery).count()); + Assert.assertEquals(0, read.query().get(getQuery).count()); } } @@ -256,37 +255,37 @@ public void testAppendAttribute(TypeDBSession session) { // Count number of total inserts try (TypeDBTransaction read = session.transaction(TypeDBTransaction.Type.READ)) { - TypeQLMatch.Limited getQuery = TypeQL.match(TypeQL.cVar("p").isa("person").has("twitter-username", TypeQL.cVar("x"))).get(TypeQL.cVar("x")).limit(1000); - Assert.assertEquals(7, read.query().match(getQuery).count()); + TypeQLGet.Limited getQuery = TypeQL.match(TypeQL.cVar("p").isa("person").has("twitter-username", TypeQL.cVar("x"))).get(TypeQL.cVar("x")).limit(1000); + Assert.assertEquals(7, read.query().get(getQuery).count()); // Count multi-write using listSeparator getQuery = TypeQL.match(TypeQL.cVar("p").isa("person").has("phone-number", "+263 498 495 0617").has("twitter-username", TypeQL.cVar("x"))).get(TypeQL.cVar("x")).limit(1000); - Assert.assertEquals(2, read.query().match(getQuery).count()); + Assert.assertEquals(2, read.query().get(getQuery).count()); //test relation total inserts getQuery = TypeQL.match(TypeQL.cVar("c").isa("call").has("call-rating", TypeQL.cVar("cr"))).get(TypeQL.cVar("c")).limit(1000); - Assert.assertEquals(5, read.query().match(getQuery).count()); + Assert.assertEquals(5, read.query().get(getQuery).count()); // specific relation write getQuery = TypeQL.match(TypeQL.cVar("c").isa("call").has("started-at", getDT("2018-09-24T03:16:48")).has("call-rating", TypeQL.cVar("cr"))).get(TypeQL.cVar("cr")).limit(1000); - read.query().match(getQuery).forEach(answer -> Assert.assertEquals(5L, answer.get("cr").asAttribute().getValue())); + read.query().get(getQuery).forEach(answer -> Assert.assertEquals(5L, answer.get("cr").asAttribute().getValue().asLong())); } } public void testInsertOrAppend(TypeDBSession session) { try (TypeDBTransaction read = session.transaction(TypeDBTransaction.Type.READ)) { - TypeQLMatch getQuery = TypeQL.match(TypeQL.cVar("e").isa("person").has("nick-name", UnboundConceptVariable.named("x"))).get(TypeQL.cVar("x")); - Assert.assertEquals(12, read.query().match(getQuery).count()); + TypeQLGet getQuery = TypeQL.match(TypeQL.cVar("e").isa("person").has("nick-name", TypeQL.cVar("x"))).get(TypeQL.cVar("x")); + Assert.assertEquals(12, read.query().get(getQuery).count()); // test new ones present (middle and at end) getQuery = TypeQL.match(TypeQL.cVar("p").isa("person").has("first-name", "Naruto")).get(TypeQL.cVar("p")).limit(1000); - Assert.assertEquals(1, read.query().match(getQuery).count()); + Assert.assertEquals(1, read.query().get(getQuery).count()); getQuery = TypeQL.match(TypeQL.cVar("p").isa("person").has("first-name", "Sasuke")).get(TypeQL.cVar("p")).limit(1000); - Assert.assertEquals(1, read.query().match(getQuery).count()); + Assert.assertEquals(1, read.query().get(getQuery).count()); getQuery = TypeQL.match(TypeQL.cVar("p").isa("person").has("first-name", "Sakura")).get(TypeQL.cVar("p")).limit(1000); - Assert.assertEquals(1, read.query().match(getQuery).count()); + Assert.assertEquals(1, read.query().get(getQuery).count()); } } } diff --git a/src/test/java/com/vaticle/typedb/osi/loader/util/QueryUtilTest.java b/src/test/java/com/vaticle/typedb/osi/loader/util/QueryUtilTest.java index f91b7ad..8b96d55 100644 --- a/src/test/java/com/vaticle/typedb/osi/loader/util/QueryUtilTest.java +++ b/src/test/java/com/vaticle/typedb/osi/loader/util/QueryUtilTest.java @@ -16,7 +16,7 @@ package com.vaticle.typedb.osi.loader.util; -import com.vaticle.typedb.client.api.TypeDBSession; +import com.vaticle.typedb.driver.api.TypeDBSession; import com.vaticle.typedb.osi.loader.config.Configuration; import java.time.LocalDate; From 69fe468dbb51ac2a44d05dd163b5f8468d955e0b Mon Sep 17 00:00:00 2001 From: joshua Date: Mon, 13 Nov 2023 10:14:12 +0000 Subject: [PATCH 2/2] Update README and build dependencies --- README.md | 21 +++++++++++---------- build.gradle | 4 ++-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 5663de7..d92a704 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ --- --- -### +### [![TypeDB Loader Test](https://github.com/bayer-science-for-a-better-life/grami/actions/workflows/testandbuild.yaml/badge.svg)](https://github.com/bayer-science-for-a-better-life/grami/actions/workflows/testandbuild.yaml) [![TypeDB Loader Build](https://github.com/bayer-science-for-a-better-life/grami/actions/workflows/release.yaml/badge.svg)](https://github.com/bayer-science-for-a-better-life/grami/actions/workflows/release.yaml) @@ -156,15 +156,16 @@ To connect to TypeDB Cluster, a set of options is provided: Ranges are [inclusive, inclusive]. | TypeDB Loader | TypeDB Driver (internal) | TypeDB | TypeDB Cluster | -|:-------------:|:----------------------:|:---------------:|:---------------:| -| 1.8.0 | 2.24.15 | 2.24.x - | 2.24.x - | -| 1.7.0 | 2.18.1 | 2.18.x 2.23.x | 2.18.x 2.23.x | -| 1.6.0 | 2.14.2 | 2.14.x - 2.17.x | 2.14.x - 2.16.x | -| 1.2.0 - 1.5.x | 2.8.0 - 2.14.0 | 2.8.0 - 2.14.0 | N/A | -| 1.1.0 - 1.1.x | 2.8.0 | 2.8.x | N/A | -| 1.0.0 | 2.5.0 - 2.7.1 | 2.5.x - 2.7.x | N/A | -| 0.1.1 | 2.0.0 - 2.4.x | 2.0.x - 2.4.x | N/A | -| <0.1 | 1.8.0 | 1.8.x | N/A | +|:-------------:|:------------------------:|:---------------:|:---------------:| +| 1.9.0 | 2.25.6 | 2.25.x - | 2.25.x - | +| 1.8.0 | 2.24.15 | 2.24.x | 2.24.x | +| 1.7.0 | 2.18.1 | 2.18.x 2.23.x | 2.18.x 2.23.x | +| 1.6.0 | 2.14.2 | 2.14.x - 2.17.x | 2.14.x - 2.16.x | +| 1.2.0 - 1.5.x | 2.8.0 - 2.14.0 | 2.8.0 - 2.14.0 | N/A | +| 1.1.0 - 1.1.x | 2.8.0 | 2.8.x | N/A | +| 1.0.0 | 2.5.0 - 2.7.1 | 2.5.x - 2.7.x | N/A | +| 0.1.1 | 2.0.0 - 2.4.x | 2.0.x - 2.4.x | N/A | +| <0.1 | 1.8.0 | 1.8.x | N/A | * [Type DB](https://github.com/vaticle/typedb) diff --git a/build.gradle b/build.gradle index d0b60d6..ec6c030 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group 'com.vaticle.typedb-osi' -version '1.8.0' +version '1.9.0' repositories { mavenCentral() @@ -15,7 +15,7 @@ repositories { } dependencies { - implementation("com.vaticle.typedb:typedb-driver:2.25.2") + implementation("com.vaticle.typedb:typedb-driver:2.25.6") implementation("com.vaticle.typeql:typeql-lang:2.25.0") implementation("com.google.code.gson:gson:2.8.6") implementation("org.slf4j:slf4j-api:1.7.25")