Skip to content

Commit

Permalink
let there be documents
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed Sep 11, 2023
1 parent 7c9cdf1 commit cb3d746
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ public static void attachError( Transaction transaction, List<Result<?, ?>> resu
Catalog catalog = Catalog.getInstance();

if ( language == QueryLanguage.from( "mongo" ) ) {
return getDocResult( statement, request, query, implementation, transaction, noLimit );
return getDocResult( statement, language, request, query, implementation, transaction, noLimit );
} else if ( language == QueryLanguage.from( "cypher" ) ) {
return getGraphResult( statement, request, query, implementation, transaction, noLimit );
return getGraphResult( statement, language, request, query, implementation, transaction, noLimit );
}

ResultIterator<PolyValue> iterator = implementation.execute( statement, noLimit ? -1 : language == QueryLanguage.from( "cypher" ) ? RuntimeConfig.UI_NODE_AMOUNT.getInteger() : RuntimeConfig.UI_PAGE_SIZE.getInteger() );
Expand Down Expand Up @@ -259,7 +259,7 @@ public static void attachError( Transaction transaction, List<Result<?, ?>> resu
}


private static GraphResult getGraphResult( Statement statement, QueryRequest request, String query, PolyImplementation<PolyValue> implementation, Transaction transaction, boolean noLimit ) {
private static GraphResult getGraphResult( Statement statement, QueryLanguage language, QueryRequest request, String query, PolyImplementation<PolyValue> implementation, Transaction transaction, boolean noLimit ) {

ResultIterator<PolyValue> iterator = implementation.execute( statement, noLimit ? -1 : RuntimeConfig.UI_PAGE_SIZE.getInteger() );
List<PolyValue[]> data = iterator.getArrayRows();
Expand All @@ -273,13 +273,15 @@ private static GraphResult getGraphResult( Statement statement, QueryRequest req
.data( data.stream().map( r -> Arrays.stream( r ).map( LanguageCrud::toJson ).toArray( String[]::new ) ).toArray( String[][]::new ) )
.header( implementation.rowType.getFieldList().stream().map( FieldDefinition::of ).toArray( FieldDefinition[]::new ) )
.query( query )
.language( language )
.namespaceType( implementation.getNamespaceType() )
.xid( transaction.getXid().toString() )
.namespaceName( Catalog.snapshot().getNamespace( request.namespaceId ).orElseThrow().name )
.build();
}


private static DocResult getDocResult( Statement statement, QueryRequest request, String query, PolyImplementation<PolyValue> implementation, Transaction transaction, boolean noLimit ) {
private static DocResult getDocResult( Statement statement, QueryLanguage language, QueryRequest request, String query, PolyImplementation<PolyValue> implementation, Transaction transaction, boolean noLimit ) {

ResultIterator<PolyValue> iterator = implementation.execute( statement, noLimit ? -1 : RuntimeConfig.UI_PAGE_SIZE.getInteger() );
List<PolyValue> data = iterator.getSingleRows();
Expand All @@ -293,7 +295,9 @@ private static DocResult getDocResult( Statement statement, QueryRequest request
.header( implementation.rowType.getFieldList().stream().map( FieldDefinition::of ).toArray( FieldDefinition[]::new ) )
.data( data.stream().map( LanguageCrud::toJson ).toArray( String[]::new ) )
.query( query )
.language( language )
.xid( transaction.getXid().toString() )
.namespaceType( implementation.getNamespaceType() )
.namespaceName( Catalog.snapshot().getNamespace( request.namespaceId ).orElseThrow().name )
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ public RelationalResult(
@JsonProperty("UIRequest") UIRequest request,
@JsonProperty("int") int affectedRows,
@JsonProperty("ResultType") ResultType type,
@JsonProperty("hasMoreRows") boolean hasMore ) {
super( namespaceType, namespaceName, data, header, exception, query, xid, error, currentPage, highestPage, hasMore );
@JsonProperty("hasMoreRows") boolean hasMore,
@JsonProperty("language") QueryLanguage language ) {
super( namespaceType, namespaceName, data, header, exception, query, xid, error, currentPage, highestPage, hasMore, language );
this.table = table;
this.tables = tables;
this.request = request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.io.IOException;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Value;
import lombok.experimental.NonFinal;
import lombok.experimental.SuperBuilder;
Expand Down Expand Up @@ -53,7 +54,6 @@ public abstract class Result<E, F> {

public String query;


/**
* Transaction id, for the websocket. It will not be serialized to gson.
*/
Expand All @@ -79,6 +79,7 @@ public abstract class Result<E, F> {
* language type of result MQL/SQL/CQL
*/
@JsonSerialize(using = LanguageSerializer.class)
@Builder.Default
public QueryLanguage language = QueryLanguage.from( "sql" );


Expand All @@ -87,6 +88,9 @@ public abstract class Result<E, F> {
*/
public static abstract class ResultBuilder<E, F, C extends Result<E, F>, B extends ResultBuilder<E, F, C, B>> {

/**
* Only necessary due to lombok builder downside
*/
protected B $fillValuesFrom( C instance ) {
this.data = instance.data;
this.namespaceType = instance.namespaceType;
Expand All @@ -95,6 +99,7 @@ public static abstract class ResultBuilder<E, F, C extends Result<E, F>, B exten
this.namespaceName = instance.namespaceName;
this.query = instance.query;
this.exception = instance.exception;
this.language$value = instance.language;

return self();
}
Expand Down

0 comments on commit cb3d746

Please sign in to comment.