Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for typedb 2.25 #74

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -153,16 +153,18 @@ To connect to TypeDB Cluster, a set of options is provided:

## Compatibility Table

Ranges are [inclusive, exclusive).
Ranges are [inclusive, inclusive].

| TypeDB Loader | TypeDB Client (internal) | TypeDB | TypeDB Cluster |
| TypeDB Loader | TypeDB Driver (internal) | TypeDB | TypeDB Cluster |
|:-------------:|:------------------------:|:---------------:|:---------------:|
| 1.7.0 | 2.18.1 | 2.18.x - | 2.18.x - |
| 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.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.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.5.0 | 2.0.x - 2.4.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)
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group 'com.vaticle.typedb-osi'
version '1.7.0'
version '1.9.0'

repositories {
mavenCentral()
Expand All @@ -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.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")
implementation("org.apache.logging.log4j:log4j-api:2.17.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<ConceptMap> answers = txn.query().match(TypeQL.match(TypeQL.cVar("t").type(conceptType)).get(TypeQL.cVar("t"))).collect(Collectors.toSet());
Set<ConceptMap> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -377,15 +377,15 @@ private boolean valConceptTypeInSchema(HashMap<String, ArrayList<String>> 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;
Expand Down Expand Up @@ -532,9 +532,9 @@ private void valRoleType(HashMap<String, ArrayList<String>> 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<ConceptMap> answers = txn.query().match(query);
Stream<ConceptMap> 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");
}
Expand All @@ -547,9 +547,9 @@ private void valRolePlayedByConcept(HashMap<String, ArrayList<String>> 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<ConceptMap> answers = txn.query().match(query);
Stream<ConceptMap> 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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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" + ">");
}
Expand All @@ -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<ThingConstraint.Predicate> constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute(
Expand All @@ -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<ThingConstraint.Predicate> constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute(
row, header, filePath, fileSeparator, attributeToAppend);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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" + ">");
}
Expand All @@ -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<ThingConstraint.Predicate> constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute(
Expand All @@ -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<ThingConstraint.Predicate> constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute(
row, header, filePath, fileSeparator, attributeToAppend);
Expand All @@ -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<ThingConstraint.Predicate> constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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" + ">");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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" + ">");
}
Expand All @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading
Loading