diff --git a/README.md b/README.md index d96dd71..2011c5d 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) @@ -129,7 +129,7 @@ public class LoadingData { ## Step-by-Step Tutorial -A complete tutorial for TypeDB version >= 2.5.0 is in work and will be published asap. +A complete tutorial for TypeDB version >= 2.5.0 is in work and will be published. An example of configuration and usage of TypeDB Loader on real data can be found [in the TypeDB Examples](https://github.com/vaticle/typedb-examples/tree/master/biology/catalogue_of_life). @@ -142,6 +142,7 @@ There is an [example repository](https://github.com/bayer-science-for-a-better-l ## Connecting to TypeDB Cluster To connect to TypeDB Cluster, a set of options is provided: + ``` --typedb-cluster= --username= @@ -154,18 +155,20 @@ To connect to TypeDB Cluster, a set of options is provided: Ranges are [inclusive, exclusive). -| TypeDB Loader | TypeDB Client (internal) | TypeDB | TypeDB Cluster | -|:--------------:|:------------------------:|:----------------:|:----------------:| -| 1.6.0 | 2.14.2 | 2.14.x to 2.16.x | 2.14.x to 2.16.x | -| 1.2.0 to 1.6.0 | 2.8.0 - 2.14.0 | 2.8.0 to 2.14.0 | N/A | -| 1.1.0 to 1.2.0 | 2.8.0 | 2.8.x | N/A | -| 1.0.0 | 2.5.0 to 2.7.1 | 2.5.x to 2.7.x | N/A | -| 0.1.1 | 2.0.0 to 2.5.0 | 2.0.x to 2.4.x | N/A | -| <0.1 | 1.8.0 | 1.8.x | N/A | +| 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 | * [Type DB](https://github.com/vaticle/typedb) -Find the Readme for GraMi for grakn < 2.0 [here](https://github.com/bayer-science-for-a-better-life/grami/blob/b3d6d272c409d6c40254354027b49f90b255e1c3/README.md) +Find the Readme for GraMi for grakn < +2.0 [here](https://github.com/bayer-science-for-a-better-life/grami/blob/b3d6d272c409d6c40254354027b49f90b255e1c3/README.md) ## Contributions diff --git a/build.gradle b/build.gradle index 1a15943..e85f12e 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group 'com.vaticle.typedb-osi' -version '1.6.0' +version '1.7.0' repositories { mavenCentral() @@ -15,8 +15,8 @@ repositories { } dependencies { - implementation("com.vaticle.typedb:typedb-client:2.14.2") - implementation("com.vaticle.typeql:typeql-grammar:2.14.0") + implementation("com.vaticle.typedb:typedb-client:2.18.1") + implementation("com.vaticle.typeql:typeql-lang:2.18.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/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 62d4c05..490fda8 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradlew b/gradlew index fbd7c51..2fe81a7 100755 --- a/gradlew +++ b/gradlew @@ -82,7 +82,6 @@ esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then @@ -130,7 +129,6 @@ fi if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath diff --git a/gradlew.bat b/gradlew.bat index 5093609..9109989 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,104 +1,103 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega 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 3f505e9..2f23fa9 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 @@ -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.var("t").type(conceptType)).get("t")).collect(Collectors.toSet()); + Set answers = txn.query().match(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 0885e9e..e7d8fe8 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 @@ -377,7 +377,7 @@ private boolean valConceptTypeInSchema(HashMap> valida String conceptType, String breadcrumbConceptType) { boolean exists = false; - TypeQLMatch query = TypeQL.match(TypeQL.var("t").type(conceptType)); + TypeQLMatch query = TypeQL.match(TypeQL.cVar("t").type(conceptType)); try (TypeDBTransaction txn = session.transaction(TypeDBTransaction.Type.READ)) { Util.trace(Integer.toString((int) txn.query().match(query).count())); exists = true; @@ -532,7 +532,7 @@ private void valRoleType(HashMap> validationReport, String breadcrumbs, String relationType, String roleType) { - TypeQLMatch query = TypeQL.match(TypeQL.type(relationType).relates(TypeQL.var("r"))).get("r"); + TypeQLMatch 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); if (answers.noneMatch(a -> a.get("r").asRoleType().getLabel().name().equals(roleType))) { @@ -547,7 +547,7 @@ private void valRolePlayedByConcept(HashMap> validatio String relationType, String role, String conceptType) { - TypeQLMatch query = TypeQL.match(TypeQL.var("c").plays(relationType, role)).get("c"); + TypeQLMatch 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); if (answers.noneMatch(c -> c.get("c").asThingType().getLabel().name().equals(conceptType))) { 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 a88ca6a..abce249 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 @@ -27,7 +27,7 @@ import com.vaticle.typeql.lang.TypeQL; import com.vaticle.typeql.lang.pattern.constraint.ThingConstraint; import com.vaticle.typeql.lang.pattern.variable.ThingVariable; -import com.vaticle.typeql.lang.pattern.variable.UnboundVariable; +import com.vaticle.typeql.lang.pattern.variable.UnboundConceptVariable; import com.vaticle.typeql.lang.query.TypeQLInsert; import org.apache.commons.io.FilenameUtils; import org.apache.logging.log4j.LogManager; @@ -87,22 +87,22 @@ public void write(TypeDBTransaction tx, String[] row, boolean allowMultiInsert) public TypeQLInsert generateMatchInsertStatement(String[] row) { if (row.length > 0) { - ThingVariable.Thing entityMatchStatement = TypeQL.var("thing") + ThingVariable.Thing entityMatchStatement = TypeQL.cVar("thing") .isa(appendConfiguration.getMatch().getType()); for (Configuration.Definition.Attribute consAtt : appendConfiguration.getMatch().getOwnerships()) { - ArrayList> constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute( + ArrayList constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute( row, header, filePath, fileSeparator, consAtt); - for (ThingConstraint.Value constraintValue : constraintValues) { + for (ThingConstraint.Predicate constraintValue : constraintValues) { entityMatchStatement.constrain(GeneratorUtil.valueToHasConstraint(consAtt.getAttribute(), constraintValue)); } } - UnboundVariable insertUnboundVar = TypeQL.var("thing"); + UnboundConceptVariable insertUnboundVar = TypeQL.cVar("thing"); ThingVariable.Thing insertStatement = null; for (Configuration.Definition.Attribute attributeToAppend : appendConfiguration.getInsert().getOwnerships()) { - ArrayList> constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute( + ArrayList constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute( row, header, filePath, fileSeparator, attributeToAppend); - for (ThingConstraint.Value constraintValue : constraintValues) { + for (ThingConstraint.Predicate constraintValue : constraintValues) { if (insertStatement == null) { insertStatement = insertUnboundVar.constrain(GeneratorUtil.valueToHasConstraint(attributeToAppend.getAttribute(), constraintValue)); } else { @@ -114,10 +114,10 @@ public TypeQLInsert generateMatchInsertStatement(String[] row) { if (insertStatement != null) { return TypeQL.match(entityMatchStatement).insert(insertStatement); } else { - return TypeQL.insert(TypeQL.var("null").isa("null").has("null", "null")); + return TypeQL.insert(TypeQL.cVar("null").isa("null").has("null", "null")); } } else { - return TypeQL.insert(TypeQL.var("null").isa("null").has("null", "null")); + return TypeQL.insert(TypeQL.cVar("null").isa("null").has("null", "null")); } } 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 d4c682d..82ff874 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 @@ -27,7 +27,7 @@ import com.vaticle.typeql.lang.TypeQL; import com.vaticle.typeql.lang.pattern.constraint.ThingConstraint; import com.vaticle.typeql.lang.pattern.variable.ThingVariable; -import com.vaticle.typeql.lang.pattern.variable.UnboundVariable; +import com.vaticle.typeql.lang.pattern.variable.UnboundConceptVariable; import com.vaticle.typeql.lang.query.TypeQLInsert; import org.apache.commons.io.FilenameUtils; import org.apache.logging.log4j.LogManager; @@ -97,22 +97,22 @@ public void write(TypeDBTransaction tx, String[] row, boolean allowMultiInsert) public TypeQLInsert generateMatchInsertStatement(String[] row) { if (row.length > 0) { - ThingVariable.Thing entityMatchStatement = TypeQL.var("thing") + ThingVariable.Thing entityMatchStatement = TypeQL.cVar("thing") .isa(appendOrInsertConfiguration.getMatch().getType()); for (Configuration.Definition.Attribute ownershipThingGetter : appendOrInsertConfiguration.getMatch().getOwnerships()) { - ArrayList> constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute( + ArrayList constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute( row, header, filePath, fileSeparator, ownershipThingGetter); - for (ThingConstraint.Value constraintValue : constraintValues) { + for (ThingConstraint.Predicate constraintValue : constraintValues) { entityMatchStatement.constrain(GeneratorUtil.valueToHasConstraint(ownershipThingGetter.getAttribute(), constraintValue)); } } - UnboundVariable insertUnboundVar = TypeQL.var("thing"); + UnboundConceptVariable insertUnboundVar = TypeQL.cVar("thing"); ThingVariable.Thing insertStatement = null; for (Configuration.Definition.Attribute attributeToAppend : appendOrInsertConfiguration.getInsert().getOwnerships()) { - ArrayList> constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute( + ArrayList constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute( row, header, filePath, fileSeparator, attributeToAppend); - for (ThingConstraint.Value constraintValue : constraintValues) { + for (ThingConstraint.Predicate constraintValue : constraintValues) { if (insertStatement == null) { insertStatement = insertUnboundVar.constrain(GeneratorUtil.valueToHasConstraint(attributeToAppend.getAttribute(), constraintValue)); } else { @@ -124,10 +124,10 @@ public TypeQLInsert generateMatchInsertStatement(String[] row) { if (insertStatement != null) { return TypeQL.match(entityMatchStatement).insert(insertStatement); } else { - return TypeQL.insert(TypeQL.var("null").isa("null").has("null", "null")); + return TypeQL.insert(TypeQL.cVar("null").isa("null").has("null", "null")); } } else { - return TypeQL.insert(TypeQL.var("null").isa("null").has("null", "null")); + return TypeQL.insert(TypeQL.cVar("null").isa("null").has("null", "null")); } } @@ -136,9 +136,9 @@ public TypeQLInsert generateThingInsertStatement(String[] row) { ThingVariable.Thing insertStatement = GeneratorUtil.generateBoundThingVar(appendOrInsertConfiguration.getMatch().getType()); for (Configuration.Definition.Attribute attribute : appendOrInsertConfiguration.getMatch().getOwnerships()) { - ArrayList> constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute( + ArrayList constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute( row, header, filePath, fileSeparator, attribute); - for (ThingConstraint.Value constraintValue : constraintValues) { + for (ThingConstraint.Predicate constraintValue : constraintValues) { insertStatement.constrain(GeneratorUtil.valueToHasConstraint(attribute.getAttribute(), constraintValue)); } } @@ -147,7 +147,7 @@ public TypeQLInsert generateThingInsertStatement(String[] row) { return TypeQL.insert(insertStatement); } else { - return TypeQL.insert(TypeQL.var("null").isa("null").has("null", "null")); + return TypeQL.insert(TypeQL.cVar("null").isa("null").has("null", "null")); } } 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 5fd11fa..2a2315e 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 @@ -76,20 +76,20 @@ public void write(TypeDBTransaction tx, String[] row, boolean allowMultiInsert) public List generateInsertStatements(String[] row) { if (row.length > 0) { - ArrayList> constraints = GeneratorUtil.generateValueConstraintsConstrainingAttribute( + ArrayList constraints = GeneratorUtil.generateValueConstraintsConstrainingAttribute( row, header, filePath, fileSeparator, attributeConfiguration.getInsert()); List insertStatements = new ArrayList<>(); - for (ThingConstraint.Value constraint : constraints) { + for (ThingConstraint.Predicate constraint : constraints) { insertStatements.add(TypeQL.insert( - TypeQL.var("a") + TypeQL.cVar("a") .constrain(constraint) .isa(attributeConfiguration.getInsert().getAttribute()) )); } return insertStatements; } else { - return List.of(TypeQL.insert(TypeQL.var("null").isa("null").has("null", "null"))); + return List.of(TypeQL.insert(TypeQL.cVar("null").isa("null").has("null", "null"))); } } 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 2a7a858..0642182 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 @@ -79,7 +79,7 @@ public TypeQLInsert generateThingInsertStatement(String[] row) { return TypeQL.insert(insertStatement); } else { - return TypeQL.insert(TypeQL.var("null").isa("null").has("null", "null")); + return TypeQL.insert(TypeQL.cVar("null").isa("null").has("null", "null")); } } 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 89cb070..1492900 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 @@ -27,7 +27,7 @@ import com.vaticle.typeql.lang.TypeQL; import com.vaticle.typeql.lang.pattern.constraint.ThingConstraint; import com.vaticle.typeql.lang.pattern.variable.ThingVariable; -import com.vaticle.typeql.lang.pattern.variable.UnboundVariable; +import com.vaticle.typeql.lang.pattern.variable.UnboundConceptVariable; import com.vaticle.typeql.lang.query.TypeQLInsert; import org.apache.commons.io.FilenameUtils; import org.apache.logging.log4j.LogManager; @@ -132,9 +132,9 @@ public TypeQLInsert generateMatchInsertStatement(String[] row) { ThingVariable.Relation insertStatement = null; for (int i = 0; i < roleTypes.size(); i++) { if (insertStatement == null) { - insertStatement = TypeQL.var("rel").rel(roleTypes.get(i), playerVars.get(i)); + insertStatement = TypeQL.cVar("rel").rel(roleTypes.get(i), TypeQL.cVar(playerVars.get(i))); } else { - insertStatement = insertStatement.rel(roleTypes.get(i), playerVars.get(i)); + insertStatement = insertStatement.rel(roleTypes.get(i), TypeQL.cVar(playerVars.get(i))); } } if (insertStatement != null) { @@ -145,19 +145,19 @@ public TypeQLInsert generateMatchInsertStatement(String[] row) { return TypeQL.match(playerMatchStatements).insert(insertStatement); } else { - return TypeQL.insert(TypeQL.var("null").isa("null").has("null", "null")); + return TypeQL.insert(TypeQL.cVar("null").isa("null").has("null", "null")); } } else { - return TypeQL.insert(TypeQL.var("null").isa("null").has("null", "null")); + return TypeQL.insert(TypeQL.cVar("null").isa("null").has("null", "null")); } } private ThingVariable.Thing getThingPlayerMatchStatementByAttribute(String[] row, Configuration.Definition.Player player, String playerVar) { - ThingVariable.Thing playerMatchStatement = TypeQL.var(playerVar).isa(player.getMatch().getType()); + ThingVariable.Thing playerMatchStatement = TypeQL.cVar(playerVar).isa(player.getMatch().getType()); for (Configuration.Definition.Attribute consA : player.getMatch().getOwnerships()) { - ArrayList> constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute( + ArrayList constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute( row, header, filePath, fileSeparator, consA); - for (ThingConstraint.Value constraintValue : constraintValues) { + for (ThingConstraint.Predicate constraintValue : constraintValues) { playerMatchStatement.constrain(GeneratorUtil.valueToHasConstraint(consA.getAttribute(), constraintValue)); } } @@ -165,10 +165,10 @@ private ThingVariable.Thing getThingPlayerMatchStatementByAttribute(String[] row } private ThingVariable.Attribute getAttributePlayerMatchStatement(String[] row, Configuration.Definition.Player player, String playerVar) { - ArrayList> constraints = GeneratorUtil.generateValueConstraintsConstrainingAttribute( + ArrayList constraints = GeneratorUtil.generateValueConstraintsConstrainingAttribute( row, header, filePath, fileSeparator, player.getMatch().getAttribute()); if (constraints.size() > 0) { - return TypeQL.var(playerVar) + return TypeQL.cVar(playerVar) .constrain(constraints.get(0)) .isa(player.getMatch().getType()); } else { @@ -203,15 +203,15 @@ private ArrayList> recursiveAssemblyMatchStatement(String[] row // identify relation player "byPlayer" ArrayList> statements = new ArrayList<>(); //create the relation statement with the player vars that will be filled in recursion: - UnboundVariable ubv = TypeQL.var(playerVar); + UnboundConceptVariable ubv = TypeQL.cVar(playerVar); ThingVariable.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; if (idx == 0) { - relationMatch = ubv.rel(curPlayer.getRole(), curPlayerVar); + relationMatch = ubv.rel(curPlayer.getRole(), TypeQL.cVar(curPlayerVar)); } else { - relationMatch = relationMatch.rel(curPlayer.getRole(), curPlayerVar); + 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); 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 ed48d72..0700eaa 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 @@ -22,6 +22,7 @@ import com.vaticle.typedb.osi.loader.type.AttributeValueType; import com.vaticle.typeql.lang.TypeQL; 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 org.apache.commons.io.FilenameUtils; @@ -55,9 +56,9 @@ public static void constrainThingWithHasAttributes(String[] row, ThingVariable insertStatement, Configuration.Definition.Attribute[] attributes) { for (Configuration.Definition.Attribute attribute : attributes) { - ArrayList> constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute( + ArrayList constraintValues = GeneratorUtil.generateValueConstraintsConstrainingAttribute( row, header, filePath, fileSeparator, attribute); - for (ThingConstraint.Value constraintValue : constraintValues) { + for (ThingConstraint.Predicate constraintValue : constraintValues) { insertStatement.constrain(GeneratorUtil.valueToHasConstraint(attribute.getAttribute(), constraintValue)); } } @@ -68,22 +69,22 @@ public static int getColumnIndexByName(String[] header, String column) { } public static ThingVariable.Thing generateBoundThingVar(String schemaType) { - return TypeQL.var("e").isa(schemaType); + return TypeQL.cVar("e").isa(schemaType); } public static ThingConstraint.Has valueToHasConstraint(String attributeSchemaType, - ThingConstraint.Value valueConstraints) { + ThingConstraint.Predicate valueConstraints) { if (valueConstraints != null) { return new ThingConstraint.Has(attributeSchemaType, valueConstraints); } return null; } - public static ArrayList> generateValueConstraintsConstrainingAttribute(String[] row, - String[] header, - String filepath, - char fileSeparator, - Configuration.Definition.Attribute attribute) { + public static ArrayList generateValueConstraintsConstrainingAttribute(String[] row, + String[] header, + String filepath, + char fileSeparator, + Configuration.Definition.Attribute attribute) { String attributeType = attribute.getAttribute(); AttributeValueType attributeValueType = attribute.getConceptValueType(); @@ -99,11 +100,11 @@ public static ArrayList> generateValueConstraintsConstr } - ArrayList> valueConstraints = new ArrayList<>(); + ArrayList valueConstraints = new ArrayList<>(); if (token != null && !token.isEmpty()) { String cleanedToken = cleanToken(token); if (listSeparator == null) { - ThingConstraint.Value valueConstraint = generateValueConstraint(attributeType, attributeValueType, cleanedToken, preprocessor, row, filepath, fileSeparator); + ThingConstraint.Predicate valueConstraint = generateValueConstraint(attributeType, attributeValueType, cleanedToken, preprocessor, row, filepath, fileSeparator); if (valueConstraint != null) { valueConstraints.add(valueConstraint); } @@ -111,7 +112,7 @@ public static ArrayList> generateValueConstraintsConstr for (String exploded : cleanedToken.split(listSeparator)) { String cleanedExplodedToken = cleanToken(exploded); if (!cleanedExplodedToken.isEmpty()) { - ThingConstraint.Value valueConstraint = generateValueConstraint(attributeType, attributeValueType, cleanedExplodedToken, preprocessor, row, filepath, fileSeparator); + ThingConstraint.Predicate valueConstraint = generateValueConstraint(attributeType, attributeValueType, cleanedExplodedToken, preprocessor, row, filepath, fileSeparator); if (valueConstraint != null) { valueConstraints.add(valueConstraint); } @@ -123,13 +124,13 @@ public static ArrayList> generateValueConstraintsConstr } - public static ThingConstraint.Value generateValueConstraint(String attributeSchemaType, - AttributeValueType attributeValueType, - String cleanedValue, - Configuration.PreprocessorConfig preprocessorConfig, - String[] row, - String filepath, - char fileSeparator) { + public static ThingConstraint.Predicate generateValueConstraint(String attributeSchemaType, + AttributeValueType attributeValueType, + String cleanedValue, + Configuration.PreprocessorConfig preprocessorConfig, + String[] row, + String filepath, + char fileSeparator) { String fileName = FilenameUtils.getName(filepath); String fileNoExtension = FilenameUtils.removeExtension(fileName); String originalRow = String.join(Character.toString(fileSeparator), row); @@ -138,14 +139,14 @@ public static ThingConstraint.Value generateValueConstraint(String attributeS cleanedValue = applyPreprocessor(cleanedValue, preprocessorConfig); } - ThingConstraint.Value constraint = null; + ThingConstraint.Predicate constraint = null; switch (attributeValueType) { case STRING: - constraint = new ThingConstraint.Value.String(TypeQLToken.Predicate.Equality.EQ, cleanedValue); + constraint = new ThingConstraint.Predicate(new Predicate.String(TypeQLToken.Predicate.Equality.EQ, cleanedValue)); break; case LONG: try { - constraint = new ThingConstraint.Value.Long(TypeQLToken.Predicate.Equality.EQ, Long.parseLong(cleanedValue)); + constraint = new ThingConstraint.Predicate(new Predicate.Long(TypeQLToken.Predicate.Equality.EQ, Long.parseLong(cleanedValue))); } catch (NumberFormatException numberFormatException) { FileLogger.getLogger().logColumnWarnings(fileName, originalRow); dataLogger.warn(String.format("column of type long for variable <%s> with non- value <%s> - skipping column - faulty row written to <%s_column_type.log>", attributeSchemaType, cleanedValue, fileNoExtension)); @@ -153,7 +154,7 @@ public static ThingConstraint.Value generateValueConstraint(String attributeS break; case DOUBLE: try { - constraint = new ThingConstraint.Value.Double(TypeQLToken.Predicate.Equality.EQ, Double.parseDouble(cleanedValue)); + constraint = new ThingConstraint.Predicate(new Predicate.Double(TypeQLToken.Predicate.Equality.EQ, Double.parseDouble(cleanedValue))); } catch (NumberFormatException numberFormatException) { FileLogger.getLogger().logColumnWarnings(fileName, originalRow); dataLogger.warn(String.format("column of type double for variable <%s> with non- value <%s> - skipping column - faulty row written to <%s_column_type.log>", attributeSchemaType, cleanedValue, fileNoExtension)); @@ -161,9 +162,9 @@ public static ThingConstraint.Value generateValueConstraint(String attributeS break; case BOOLEAN: if (cleanedValue.equalsIgnoreCase("true")) { - constraint = new ThingConstraint.Value.Boolean(TypeQLToken.Predicate.Equality.EQ, true); + constraint = new ThingConstraint.Predicate(new Predicate.Boolean(TypeQLToken.Predicate.Equality.EQ, true)); } else if (cleanedValue.equalsIgnoreCase("false")) { - constraint = new ThingConstraint.Value.Boolean(TypeQLToken.Predicate.Equality.EQ, false); + constraint = new ThingConstraint.Predicate(new Predicate.Boolean(TypeQLToken.Predicate.Equality.EQ, false)); } else { FileLogger.getLogger().logColumnWarnings(fileName, originalRow); dataLogger.warn(String.format("column of type boolean for variable <%s> with non- value <%s> - skipping column - faulty row written to <%s_column_type.log>", attributeSchemaType, cleanedValue, fileNoExtension)); @@ -181,7 +182,7 @@ public static ThingConstraint.Value generateValueConstraint(String attributeS } else { dateTime = date.atStartOfDay(); } - constraint = new ThingConstraint.Value.DateTime(TypeQLToken.Predicate.Equality.EQ, dateTime); + constraint = new ThingConstraint.Predicate(new Predicate.DateTime(TypeQLToken.Predicate.Equality.EQ, dateTime)); } catch (DateTimeException dateTimeException) { FileLogger.getLogger().logColumnWarnings(fileName, originalRow); dataLogger.warn(String.format("column of type datetime for variable <%s> with non- datetime value <%s> - skipping column - faulty row written to <%s_column_type.log>", attributeSchemaType, cleanedValue, fileNoExtension)); 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 fc9d232..aeccd9d 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 @@ -134,10 +134,10 @@ public static TypeQLInsert replaceMatchWithAnswer(TypeQLInsert query, ConceptMap List> insertVars = query.asInsert().variables(); List matchVars = new ArrayList<>(); ans.map().forEach((var, concept) -> { - if (concept.isThing()) matchVars.add(TypeQL.var(var).iid(concept.asThing().getIID())); + if (concept.isThing()) matchVars.add(TypeQL.cVar(var).iid(concept.asThing().getIID())); else if (concept.asType().getLabel().scope().isPresent()) { - matchVars.add(TypeQL.var(var).type(concept.asType().getLabel().scope().get(), concept.asType().getLabel().name())); - } else matchVars.add(TypeQL.var(var).type(concept.asType().getLabel().name())); + matchVars.add(TypeQL.cVar(var).type(concept.asType().getLabel().scope().get(), concept.asType().getLabel().name())); + } else matchVars.add(TypeQL.cVar(var).type(concept.asType().getLabel().name())); }); return TypeQL.match(matchVars).insert(insertVars); } 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 14d1409..893b150 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 @@ -23,7 +23,7 @@ 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.UnboundVariable; +import com.vaticle.typeql.lang.pattern.variable.UnboundConceptVariable; import com.vaticle.typeql.lang.query.TypeQLMatch; import org.junit.Assert; import org.junit.Test; @@ -86,16 +86,16 @@ public void loadPhoneCallsTest() { public void testAttributes(TypeDBSession session) { try (TypeDBTransaction read = session.transaction(TypeDBTransaction.Type.READ)) { - TypeQLMatch getQuery = TypeQL.match(TypeQL.var("a").isa("is-in-use")).get("a"); + TypeQLMatch getQuery = TypeQL.match(TypeQL.cVar("a").isa("is-in-use")).get(TypeQL.cVar("a")); Assert.assertEquals(3, read.query().match(getQuery).count()); - getQuery = TypeQL.match(TypeQL.var("a").eq("yes").isa("is-in-use")).get("a"); + getQuery = TypeQL.match(TypeQL.cVar("a").eq("yes").isa("is-in-use")).get(TypeQL.cVar("a")); Assert.assertEquals(1, read.query().match(getQuery).count()); - getQuery = TypeQL.match(TypeQL.var("a").eq("no").isa("is-in-use")).get("a"); + getQuery = TypeQL.match(TypeQL.cVar("a").eq("no").isa("is-in-use")).get(TypeQL.cVar("a")); Assert.assertEquals(1, read.query().match(getQuery).count()); - getQuery = TypeQL.match(TypeQL.var("a").eq("5").isa("is-in-use")).get("a"); + getQuery = TypeQL.match(TypeQL.cVar("a").eq("5").isa("is-in-use")).get(TypeQL.cVar("a")); Assert.assertEquals(1, read.query().match(getQuery).count()); } } @@ -104,19 +104,19 @@ public void testEntities(TypeDBSession session) { // query person by phone-number try (TypeDBTransaction read = session.transaction(TypeDBTransaction.Type.READ)) { - TypeQLMatch getQuery = TypeQL.match(TypeQL.var("p").isa("person").has("phone-number", "+261 860 539 4754")).get("p").limit(1000); + 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()); // query person by last name - getQuery = TypeQL.match(TypeQL.var("p").isa("person").has("last-name", "Smith")).get("p").limit(1000); + 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()); // query all entities of type person - getQuery = TypeQL.match(TypeQL.var("c").isa("person")).get("c").limit(1000); + getQuery = TypeQL.match(TypeQL.cVar("c").isa("person")).get(TypeQL.cVar("c")).limit(1000); Assert.assertEquals(39, read.query().match(getQuery).count()); // query all entites of type company - getQuery = TypeQL.match(TypeQL.var("e").isa("company")).get("e").limit(1000); + getQuery = TypeQL.match(TypeQL.cVar("e").isa("company")).get(TypeQL.cVar("e")).limit(1000); Assert.assertEquals(2, read.query().match(getQuery).count()); } } @@ -125,40 +125,40 @@ public void testRelations(TypeDBSession session) { // query call by duration try (TypeDBTransaction read = session.transaction(TypeDBTransaction.Type.READ)) { - TypeQLMatch getQuery = TypeQL.match(TypeQL.var("c").isa("call").has("duration", 2851)).get("c").limit(1000); + 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()); // query call by date - getQuery = TypeQL.match(TypeQL.var("c").isa("call").has("started-at", getDT("2018-09-17T18:43:42"))).get("c").limit(1000); + 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()); // query call by caller - ThingVariable.Thing player = TypeQL.var("p").isa("person").has("phone-number", "+7 171 898 0853"); - ThingVariable.Relation relation = TypeQL.var("c").isa("call").toUnbound().rel("caller", "p"); + 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<>(); statements.add(player); statements.add(relation); - getQuery = TypeQL.match(statements).get("c").limit(1000); + getQuery = TypeQL.match(statements).get(TypeQL.cVar("c")).limit(1000); Assert.assertEquals(14, read.query().match(getQuery).count()); // query call by callee - player = TypeQL.var("p").isa("person").has("phone-number", "+7 171 898 0853"); - relation = TypeQL.var("c").isa("call").toUnbound().rel("callee", "p"); + 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")); statements = new ArrayList<>(); statements.add(player); statements.add(relation); - getQuery = TypeQL.match(statements).get("c").limit(1000); + getQuery = TypeQL.match(statements).get(TypeQL.cVar("c")).limit(1000); Assert.assertEquals(4, read.query().match(getQuery).count()); // query call by caller & callee - ThingVariable.Thing playerOne = TypeQL.var("p1").isa("person").has("phone-number", "+7 171 898 0853"); - ThingVariable.Thing playerTwo = TypeQL.var("p2").isa("person").has("phone-number", "+57 629 420 5680"); - relation = TypeQL.var("c").isa("call").toUnbound().rel("caller", "p1").rel("callee", "p2"); + 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")); statements = new ArrayList<>(); statements.add(playerOne); statements.add(playerTwo); statements.add(relation); - getQuery = TypeQL.match(statements).get("c").limit(1000); + getQuery = TypeQL.match(statements).get(TypeQL.cVar("c")).limit(1000); Assert.assertEquals(4, read.query().match(getQuery).count()); } } @@ -166,7 +166,7 @@ public void testRelations(TypeDBSession session) { public void testAttributeRelation(TypeDBSession session) { TypeDBTransaction read = session.transaction(TypeDBTransaction.Type.READ); - TypeQLMatch getQuery = TypeQL.match(TypeQL.var("a").isa("in-use")).get("a"); + TypeQLMatch getQuery = TypeQL.match(TypeQL.cVar("a").isa("in-use")).get(TypeQL.cVar("a")); Assert.assertEquals(7, read.query().match(getQuery).count()); read.close(); @@ -176,78 +176,78 @@ 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.var("p1").isa("person").has("phone-number", "+54 398 559 0423"); - ThingVariable.Thing playerTwo = TypeQL.var("p2").isa("person").has("phone-number", "+48 195 624 2025"); - ThingVariable.Relation relation = TypeQL.var("c").rel("peer", "p1").rel("peer", "p2").rel("past-call", "x").isa("communication-channel"); + 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<>(); statements.add(playerOne); statements.add(playerTwo); statements.add(relation); - TypeQLMatch getQuery = TypeQL.match(statements).get("c").limit(1000); + TypeQLMatch getQuery = TypeQL.match(statements).get(TypeQL.cVar("c")).limit(1000); Assert.assertEquals(1, read.query().match(getQuery).count()); - getQuery = TypeQL.match(statements).get("x").limit(1000); + getQuery = TypeQL.match(statements).get(TypeQL.cVar("x")).limit(1000); Assert.assertEquals(1, read.query().match(getQuery).count()); // query specific communication-channel and count the number of past calls (listSeparated past-calls: - playerOne = TypeQL.var("p1").isa("person").has("phone-number", "+263 498 495 0617"); - playerTwo = TypeQL.var("p2").isa("person").has("phone-number", "+33 614 339 0298"); - relation = TypeQL.var("c").rel("peer", "p1").rel("peer", "p2").rel("past-call", "x").isa("communication-channel"); + playerOne = TypeQL.cVar("p1").isa("person").has("phone-number", "+263 498 495 0617"); + playerTwo = TypeQL.cVar("p2").isa("person").has("phone-number", "+33 614 339 0298"); + relation = TypeQL.cVar("c").rel("peer", TypeQL.cVar("p1")).rel("peer", TypeQL.cVar("p2")).rel("past-call", TypeQL.cVar("x")).isa("communication-channel"); statements = new ArrayList<>(); statements.add(playerOne); statements.add(playerTwo); statements.add(relation); - getQuery = TypeQL.match(statements).get("c").limit(1000); + getQuery = TypeQL.match(statements).get(TypeQL.cVar("c")).limit(1000); Assert.assertEquals(1, read.query().match(getQuery).count()); - getQuery = TypeQL.match(statements).get("x").limit(1000); + getQuery = TypeQL.match(statements).get(TypeQL.cVar("x")).limit(1000); Assert.assertEquals(1, read.query().match(getQuery).count()); // make sure that this doesn't get inserted: - playerOne = TypeQL.var("p1").isa("person").has("phone-number", "+7 690 597 4443"); - playerTwo = TypeQL.var("p2").isa("person").has("phone-number", "+54 398 559 9999"); - relation = TypeQL.var("c").rel("peer", "p1").rel("peer", "p2").rel("past-call", "x").isa("communication-channel"); + playerOne = TypeQL.cVar("p1").isa("person").has("phone-number", "+7 690 597 4443"); + playerTwo = TypeQL.cVar("p2").isa("person").has("phone-number", "+54 398 559 9999"); + relation = TypeQL.cVar("c").rel("peer", TypeQL.cVar("p1")).rel("peer", TypeQL.cVar("p2")).rel("past-call", TypeQL.cVar("x")).isa("communication-channel"); statements = new ArrayList<>(); statements.add(playerOne); statements.add(playerTwo); statements.add(relation); - getQuery = TypeQL.match(statements).get("c").limit(1000); + getQuery = TypeQL.match(statements).get(TypeQL.cVar("c")).limit(1000); Assert.assertEquals(0, read.query().match(getQuery).count()); - getQuery = TypeQL.match(statements).get("x").limit(1000); + getQuery = TypeQL.match(statements).get(TypeQL.cVar("x")).limit(1000); Assert.assertEquals(0, read.query().match(getQuery).count()); // these are added by doing player matching for past calls: - playerOne = TypeQL.var("p1").isa("person").has("phone-number", "+81 308 988 7153"); - playerTwo = TypeQL.var("p2").isa("person").has("phone-number", "+351 515 605 7915"); - relation = TypeQL.var("c").rel("peer", "p1").rel("peer", "p2").rel("past-call", "x").isa("communication-channel"); + playerOne = TypeQL.cVar("p1").isa("person").has("phone-number", "+81 308 988 7153"); + playerTwo = TypeQL.cVar("p2").isa("person").has("phone-number", "+351 515 605 7915"); + relation = TypeQL.cVar("c").rel("peer", TypeQL.cVar("p1")).rel("peer", TypeQL.cVar("p2")).rel("past-call", TypeQL.cVar("x")).isa("communication-channel"); statements = new ArrayList<>(); statements.add(playerOne); statements.add(playerTwo); statements.add(relation); - getQuery = TypeQL.match(statements).get("c").limit(1000); + getQuery = TypeQL.match(statements).get(TypeQL.cVar("c")).limit(1000); Assert.assertEquals(5, read.query().match(getQuery).count()); - getQuery = TypeQL.match(statements).get("x").limit(1000); + getQuery = TypeQL.match(statements).get(TypeQL.cVar("x")).limit(1000); Assert.assertEquals(5, read.query().match(getQuery).count()); - playerOne = TypeQL.var("p1").isa("person").has("phone-number", "+7 171 898 0853"); - playerTwo = TypeQL.var("p2").isa("person").has("phone-number", "+57 629 420 5680"); - relation = TypeQL.var("c").rel("peer", "p1").rel("peer", "p2").rel("past-call", "x").isa("communication-channel"); + 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"); + relation = TypeQL.cVar("c").rel("peer", TypeQL.cVar("p1")).rel("peer", TypeQL.cVar("p2")).rel("past-call", TypeQL.cVar("x")).isa("communication-channel"); statements = new ArrayList<>(); statements.add(playerOne); statements.add(playerTwo); statements.add(relation); - getQuery = TypeQL.match(statements).get("c").limit(1000); + getQuery = TypeQL.match(statements).get(TypeQL.cVar("c")).limit(1000); Assert.assertEquals(4, read.query().match(getQuery).count()); - getQuery = TypeQL.match(statements).get("x").limit(1000); + getQuery = TypeQL.match(statements).get(TypeQL.cVar("x")).limit(1000); Assert.assertEquals(4, read.query().match(getQuery).count()); // these must not be found (come from player-matched past-call): - playerOne = TypeQL.var("p1").isa("person").has("phone-number", "+261 860 539 4754"); - relation = TypeQL.var("c").rel("peer", "p1").rel("past-call", "x").isa("communication-channel"); + playerOne = TypeQL.cVar("p1").isa("person").has("phone-number", "+261 860 539 4754"); + relation = TypeQL.cVar("c").rel("peer", TypeQL.cVar("p1")).rel("past-call", TypeQL.cVar("x")).isa("communication-channel"); statements = new ArrayList<>(); statements.add(playerOne); statements.add(relation); - getQuery = TypeQL.match(statements).get("c").limit(1000); + getQuery = TypeQL.match(statements).get(TypeQL.cVar("c")).limit(1000); Assert.assertEquals(0, read.query().match(getQuery).count()); - getQuery = TypeQL.match(statements).get("x").limit(1000); + getQuery = TypeQL.match(statements).get(TypeQL.cVar("x")).limit(1000); Assert.assertEquals(0, read.query().match(getQuery).count()); } } @@ -256,36 +256,36 @@ public void testAppendAttribute(TypeDBSession session) { // Count number of total inserts try (TypeDBTransaction read = session.transaction(TypeDBTransaction.Type.READ)) { - TypeQLMatch.Limited getQuery = TypeQL.match(TypeQL.var("p").isa("person").has("twitter-username", TypeQL.var("x"))).get("x").limit(1000); + 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()); // Count multi-write using listSeparator - getQuery = TypeQL.match(TypeQL.var("p").isa("person").has("phone-number", "+263 498 495 0617").has("twitter-username", TypeQL.var("x"))).get("x").limit(1000); + 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()); //test relation total inserts - getQuery = TypeQL.match(TypeQL.var("c").isa("call").has("call-rating", TypeQL.var("cr"))).get("c").limit(1000); + 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()); // specific relation write - getQuery = TypeQL.match(TypeQL.var("c").isa("call").has("started-at", getDT("2018-09-24T03:16:48")).has("call-rating", TypeQL.var("cr"))).get("cr").limit(1000); + 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())); } } public void testInsertOrAppend(TypeDBSession session) { try (TypeDBTransaction read = session.transaction(TypeDBTransaction.Type.READ)) { - TypeQLMatch getQuery = TypeQL.match(TypeQL.var("e").isa("person").has("nick-name", UnboundVariable.named("x"))).get("x"); + 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()); // test new ones present (middle and at end) - getQuery = TypeQL.match(TypeQL.var("p").isa("person").has("first-name", "Naruto")).get("p").limit(1000); + 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()); - getQuery = TypeQL.match(TypeQL.var("p").isa("person").has("first-name", "Sasuke")).get("p").limit(1000); + 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()); - getQuery = TypeQL.match(TypeQL.var("p").isa("person").has("first-name", "Sakura")).get("p").limit(1000); + 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()); } }