2525import com .vaticle .typedb .driver .api .TypeDBTransaction ;
2626import com .vaticle .typedb .driver .api .answer .ConceptMap ;
2727import com .vaticle .typedb .driver .api .answer .ConceptMapGroup ;
28- import com .vaticle .typedb .driver .api .answer .Numeric ;
29- import com .vaticle .typedb .driver .api .answer .NumericGroup ;
28+ import com .vaticle .typedb .driver .api .answer .JSON ;
29+ import com .vaticle .typedb .driver .api .answer .ValueGroup ;
30+ import com .vaticle .typedb .driver .api .concept .value .Value ;
3031import com .vaticle .typedb .driver .api .database .Database ;
3132import com .vaticle .typedb .driver .api .user .User ;
3233import com .vaticle .typedb .driver .common .exception .TypeDBDriverException ;
4142import com .vaticle .typeql .lang .common .exception .TypeQLException ;
4243import com .vaticle .typeql .lang .query .TypeQLDefine ;
4344import com .vaticle .typeql .lang .query .TypeQLDelete ;
45+ import com .vaticle .typeql .lang .query .TypeQLFetch ;
4446import com .vaticle .typeql .lang .query .TypeQLInsert ;
45- import com .vaticle .typeql .lang .query .TypeQLMatch ;
47+ import com .vaticle .typeql .lang .query .TypeQLGet ;
4648import com .vaticle .typeql .lang .query .TypeQLQuery ;
4749import com .vaticle .typeql .lang .query .TypeQLUndefine ;
4850import com .vaticle .typeql .lang .query .TypeQLUpdate ;
@@ -148,11 +150,7 @@ private static CLIOptions parseCLIOptions(String[] args) {
148150 try {
149151 int exitCode = CLI .execute (args );
150152 if (exitCode == 0 ) {
151- if (CLI .isUsageHelpRequested ()) {
152- CLI .usage (CLI .getOut ());
153- System .exit (0 );
154- } else if (CLI .isVersionHelpRequested ()) {
155- CLI .printVersionHelp (CLI .getOut ());
153+ if (CLI .isUsageHelpRequested () || CLI .isVersionHelpRequested ()) {
156154 System .exit (0 );
157155 } else {
158156 return options ;
@@ -321,7 +319,6 @@ private boolean transactionREPL(TypeDBDriver driver, boolean isEnterprise, Strin
321319 }
322320 if (command .isSecond ()) {
323321 printer .error (command .second ());
324- continue ;
325322 } else {
326323 TransactionREPLCommand replCommand = command .first ();
327324 if (replCommand .isExit ()) {
@@ -364,7 +361,7 @@ private boolean runScriptMode(CLIOptions options, String script) {
364361 }
365362
366363 private boolean runInlineCommandMode (CLIOptions options , List <String > inlineCommands ) {
367- inlineCommands = inlineCommands .stream ().map (x -> x . trim () ).filter (x -> !x .isEmpty ()).collect (toList ());
364+ inlineCommands = inlineCommands .stream ().map (String :: trim ).filter (x -> !x .isEmpty ()).collect (toList ());
368365 boolean [] cancelled = new boolean []{false };
369366 terminal .handle (Terminal .Signal .INT , s -> cancelled [0 ] = true );
370367 boolean isEnterprise = options .enterprise () != null ;
@@ -674,15 +671,15 @@ private RunQueriesResult runSource(TypeDBTransaction tx, String file, boolean pr
674671
675672 private RunQueriesResult runQueries (TypeDBTransaction tx , String queryString ) {
676673 Optional <List <TypeQLQuery >> queries = parseQueries (queryString );
677- if (! queries .isPresent ()) return RunQueriesResult .error ();
678- queries .get ().stream (). forEach (query -> runQuery (tx , query ));
674+ if (queries .isEmpty ()) return RunQueriesResult .error ();
675+ queries .get ().forEach (query -> runQuery (tx , query ));
679676 boolean hasChanges = queries .get ().stream ().anyMatch (query -> query .type () == TypeQLArg .QueryType .WRITE );
680677 return new RunQueriesResult (true , hasChanges );
681678 }
682679
683680 private RunQueriesResult runQueriesPrintAnswers (TypeDBTransaction tx , String queryString ) {
684681 Optional <List <TypeQLQuery >> queries = parseQueries (queryString );
685- if (! queries .isPresent ()) return RunQueriesResult .error ();
682+ if (queries .isEmpty ()) return RunQueriesResult .error ();
686683 queries .get ().forEach (query -> runQueryPrintAnswers (tx , query ));
687684 boolean hasChanges = queries .get ().stream ().anyMatch (query -> query .type () == TypeQLArg .QueryType .WRITE );
688685 return new RunQueriesResult (true , hasChanges );
@@ -691,37 +688,39 @@ private RunQueriesResult runQueriesPrintAnswers(TypeDBTransaction tx, String que
691688 @ SuppressWarnings ("CheckReturnValue" )
692689 private void runQuery (TypeDBTransaction tx , TypeQLQuery query ) {
693690 if (query instanceof TypeQLDefine ) {
694- tx .query ().define (query .asDefine ());
691+ tx .query ().define (query .asDefine ()). resolve () ;
695692 printer .info ("Concepts have been defined" );
696693 } else if (query instanceof TypeQLUndefine ) {
697- tx .query ().undefine (query .asUndefine ());
694+ tx .query ().undefine (query .asUndefine ()). resolve () ;
698695 printer .info ("Concepts have been undefined" );
699696 } else if (query instanceof TypeQLInsert ) {
700697 Optional <ConceptMap > ignore = tx .query ().insert (query .asInsert ()).findFirst ();
701698 } else if (query instanceof TypeQLDelete ) {
702- tx .query ().delete (query .asDelete ());
699+ tx .query ().delete (query .asDelete ()). resolve () ;
703700 } else if (query instanceof TypeQLUpdate ) {
704701 Optional <ConceptMap > ignore = tx .query ().update (query .asUpdate ()).findFirst ();
705- } else if (query instanceof TypeQLMatch ) {
706- Optional <ConceptMap > ignore = tx .query ().match (query .asMatch ()).findFirst ();
707- } else if (query instanceof TypeQLMatch .Aggregate ) {
708- Numeric ignore = tx .query ().match (query .asMatchAggregate ());
709- } else if (query instanceof TypeQLMatch .Group ) {
710- Optional <ConceptMapGroup > ignore = tx .query ().match (query .asMatchGroup ()).findFirst ();
711- } else if (query instanceof TypeQLMatch .Group .Aggregate ) {
712- Optional <NumericGroup > ignore = tx .query ().match (query .asMatchGroupAggregate ()).findFirst ();
702+ } else if (query instanceof TypeQLGet ) {
703+ Optional <ConceptMap > ignore = tx .query ().get (query .asGet ()).findFirst ();
704+ } else if (query instanceof TypeQLGet .Aggregate ) {
705+ Optional <Value > ignore = tx .query ().get (query .asGetAggregate ()).resolve ();
706+ } else if (query instanceof TypeQLGet .Group ) {
707+ Optional <ConceptMapGroup > ignore = tx .query ().get (query .asGetGroup ()).findFirst ();
708+ } else if (query instanceof TypeQLGet .Group .Aggregate ) {
709+ Optional <ValueGroup > ignore = tx .query ().get (query .asGetGroupAggregate ()).findFirst ();
710+ } else if (query instanceof TypeQLFetch ) {
711+ Optional <JSON > ignore = tx .query ().fetch (query .asFetch ()).findFirst ();
713712 } else {
714713 throw new TypeDBConsoleException ("Query is of unrecognized type: " + query );
715714 }
716715 }
717716
718717 private void runQueryPrintAnswers (TypeDBTransaction tx , TypeQLQuery query ) {
719718 if (query instanceof TypeQLDefine ) {
720- tx .query ().define (query .asDefine ());
719+ tx .query ().define (query .asDefine ()). resolve () ;
721720 printer .info ("Concepts have been defined" );
722721 hasUncommittedChanges = true ;
723722 } else if (query instanceof TypeQLUndefine ) {
724- tx .query ().undefine (query .asUndefine ());
723+ tx .query ().undefine (query .asUndefine ()). resolve () ;
725724 printer .info ("Concepts have been undefined" );
726725 hasUncommittedChanges = true ;
727726 } else if (query instanceof TypeQLInsert ) {
@@ -733,9 +732,11 @@ private void runQueryPrintAnswers(TypeDBTransaction tx, TypeQLQuery query) {
733732 });
734733 if (changed .get ()) hasUncommittedChanges = true ;
735734 } else if (query instanceof TypeQLDelete ) {
736- long limitedCount = tx .query ().match (query .asDelete ().match ()).limit (20 ).count ();
735+ Optional <TypeQLQuery .MatchClause > match = query .asDelete ().match ();
736+ assert match .isPresent ();
737+ long limitedCount = tx .query ().get (match .get ().get ()).limit (20 ).count ();
737738 if (limitedCount > 0 ) {
738- tx .query ().delete (query .asDelete ());
739+ tx .query ().delete (query .asDelete ()). resolve () ;
739740 if (limitedCount == 20 ) printer .info ("Deleted from 20+ matched answers" );
740741 else printer .info ("Deleted from " + limitedCount + " matched answer(s)" );
741742 hasUncommittedChanges = true ;
@@ -750,17 +751,20 @@ private void runQueryPrintAnswers(TypeDBTransaction tx, TypeQLQuery query) {
750751 printer .conceptMap (x , tx );
751752 });
752753 if (changed .get ()) hasUncommittedChanges = true ;
753- } else if (query instanceof TypeQLMatch ) {
754- Stream <ConceptMap > result = tx .query ().match (query .asMatch ());
754+ } else if (query instanceof TypeQLGet ) {
755+ Stream <ConceptMap > result = tx .query ().get (query .asGet ());
755756 printCancellableResult (result , x -> printer .conceptMap (x , tx ));
756- } else if (query instanceof TypeQLMatch .Aggregate ) {
757- printer .numeric (tx .query ().match (query .asMatchAggregate () ));
758- } else if (query instanceof TypeQLMatch .Group ) {
759- Stream <ConceptMapGroup > result = tx .query ().match (query .asMatchGroup ());
757+ } else if (query instanceof TypeQLGet .Aggregate ) {
758+ printer .value (tx .query ().get (query .asGetAggregate ()). resolve (). orElse ( null ));
759+ } else if (query instanceof TypeQLGet .Group ) {
760+ Stream <ConceptMapGroup > result = tx .query ().get (query .asGetGroup ());
760761 printCancellableResult (result , x -> printer .conceptMapGroup (x , tx ));
761- } else if (query instanceof TypeQLMatch .Group .Aggregate ) {
762- Stream <NumericGroup > result = tx .query ().match (query .asMatchGroupAggregate ());
763- printCancellableResult (result , x -> printer .numericGroup (x , tx ));
762+ } else if (query instanceof TypeQLGet .Group .Aggregate ) {
763+ Stream <ValueGroup > result = tx .query ().get (query .asGetGroupAggregate ());
764+ printCancellableResult (result , x -> printer .valueGroup (x , tx ));
765+ } else if (query instanceof TypeQLFetch ) {
766+ Stream <JSON > result = tx .query ().fetch (query .asFetch ());
767+ printCancellableResult (result , printer ::json );
764768 } else {
765769 throw new TypeDBConsoleException ("Query is of unrecognized type: " + query );
766770 }
@@ -790,15 +794,19 @@ private <T> void printCancellableResult(Stream<T> results, Consumer<T> printFn)
790794 prevHandler = terminal .handle (Terminal .Signal .INT , s -> answerPrintingJob .cancel (true ));
791795 answerPrintingJob .get ();
792796 Instant end = Instant .now ();
793- printer .info ("answers: " + counter [0 ] + ", total (with concept details) duration: " + Duration .between (start , end ).toMillis () + " ms" );
797+ printer .info ("" );
798+ printer .info ("answers: " + counter [0 ] + ", total duration: " + Duration .between (start , end ).toMillis () + " ms" );
799+ printer .info ("" );
794800 } catch (InterruptedException e ) {
795801 e .printStackTrace ();
796802 } catch (ExecutionException e ) {
797803 throw (TypeDBDriverException ) e .getCause ();
798804 } catch (CancellationException e ) {
799805 Instant end = Instant .now ();
800- printer .info ("answers: " + counter [0 ] + ", total (with concept details) duration: " + Duration .between (start , end ).toMillis () + " ms" );
806+ printer .info ("" );
807+ printer .info ("answers: " + counter [0 ] + ", total duration: " + Duration .between (start , end ).toMillis () + " ms" );
801808 printer .info ("The query has been cancelled. It may take some time for the cancellation to finish on the server side." );
809+ printer .info ("" );
802810 } finally {
803811 if (prevHandler != null ) terminal .handle (Terminal .Signal .INT , prevHandler );
804812 }
0 commit comments