Skip to content

Commit

Permalink
fixes for multiple queries results
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed Apr 2, 2024
1 parent 8964aee commit 94d72cb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
16 changes: 10 additions & 6 deletions core/src/main/java/org/polypheny/db/languages/LanguageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ public static void removeQueryLanguage( String name ) {
}


public List<ImplementationContext> anyPrepareQuery( QueryContext context, Statement statement ) {
Transaction transaction = statement.getTransaction();

public List<ImplementationContext> anyPrepareQuery( QueryContext context, Transaction transaction ) {
Statement statement = transaction.createStatement();
if ( transaction.isAnalyze() ) {
context.getInformationTarget().accept( transaction.getQueryAnalyzer() );
}
Expand Down Expand Up @@ -118,7 +117,11 @@ public List<ImplementationContext> anyPrepareQuery( QueryContext context, Statem
Processor processor = context.getLanguage().processorSupplier().get();
List<ImplementationContext> implementationContexts = new ArrayList<>();
boolean previousDdl = false;
int i = 0;
for ( ParsedQueryContext parsed : parsedQueries ) {
if ( i != 0 ) {
statement = transaction.createStatement();
}
try {
// test if parsing was successful
if ( parsed.getQueryNode().isEmpty() ) {
Expand Down Expand Up @@ -191,6 +194,7 @@ public List<ImplementationContext> anyPrepareQuery( QueryContext context, Statem
implementationContexts.add( ImplementationContext.ofError( e, parsed, statement ) );
return implementationContexts;
}
i++;
}
return implementationContexts;
}
Expand Down Expand Up @@ -218,9 +222,8 @@ private static void cancelTransaction( @Nullable Transaction transaction ) {
}


public List<ExecutedContext> anyQuery( QueryContext context, Statement statement ) {
List<ImplementationContext> prepared = anyPrepareQuery( context, statement );
Transaction transaction = statement.getTransaction();
public List<ExecutedContext> anyQuery( QueryContext context ) {
List<ImplementationContext> prepared = anyPrepareQuery( context, context.getTransactions().get( context.getTransactions().size() - 1 ) );

List<ExecutedContext> executedContexts = new ArrayList<>();

Expand All @@ -231,6 +234,7 @@ public List<ExecutedContext> anyQuery( QueryContext context, Statement statement
}
executedContexts.add( implementation.execute( implementation.getStatement() ) );
} catch ( Throwable e ) {
Transaction transaction = implementation.getStatement().getTransaction();
if ( transaction.isAnalyze() && implementation.getException().isEmpty() ) {
transaction.getQueryAnalyzer().attachStacktrace( e );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ private void prepare( StatementHandle h, String sql ) throws NoSuchStatementExce
.transactionManager( transactionManager )
.build();

PolySignature signature = PolySignature.from( LanguageManager.getINSTANCE().anyPrepareQuery( context, statementHandle.getStatement() ).get( 0 ) );
PolySignature signature = PolySignature.from( LanguageManager.getINSTANCE().anyPrepareQuery( context, statementHandle.getStatement().getTransaction() ).get( 0 ) );

h.signature = signature;
statementHandle.setSignature( signature );
Expand Down
15 changes: 7 additions & 8 deletions webui/src/main/java/org/polypheny/db/webui/Crud.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,16 +287,15 @@ RelationalResult getTable( final UIRequest request ) {

TriFunction<ExecutedContext, UIRequest, Statement, ResultBuilder<?, ?, ?, ?>> builder = LanguageCrud.getToResult( language );

Statement statement = transaction.createStatement();
ImplementationContext implementationContext = LanguageManager.getINSTANCE().anyPrepareQuery(
QueryContext.builder()
.query( query.toString() )
.language( language )
.origin( transaction.getOrigin() )
.batch( request.noLimit ? -1 : getPageSize() )
.transactionManager( transactionManager )
.build(), statement ).get( 0 );
resultBuilder = (RelationalResultBuilder<?, ?>) builder.apply( implementationContext.execute( statement ), request, statement );//.executeSqlSelect( transaction.createStatement(), request, query.toString(), request.noLimit, this );
.build(), transaction ).get( 0 );
resultBuilder = (RelationalResultBuilder<?, ?>) builder.apply( implementationContext.execute( implementationContext.getStatement() ), request, implementationContext.getStatement() );

// determine if it is a view or a table
LogicalTable table = Catalog.snapshot().rel().getTable( request.entityId ).orElseThrow();
Expand Down Expand Up @@ -2835,22 +2834,22 @@ private long getTableSize( Transaction transaction, final UIRequest request ) {
if ( request.filter != null ) {
query += " " + filterTable( request.filter );
}
Statement statement = transaction.createStatement();

QueryLanguage language = QueryLanguage.from( "sql" );
ImplementationContext context = LanguageManager.getINSTANCE().anyPrepareQuery(
QueryContext.builder()
.query( query )
.language( language )
.origin( ORIGIN )
.transactionManager( transactionManager ).build(), statement ).get( 0 );
List<List<PolyValue>> values = context.execute( statement ).getIterator().getNextBatch();
.transactionManager( transactionManager ).build(), transaction ).get( 0 );
List<List<PolyValue>> values = context.execute( context.getStatement() ).getIterator().getNextBatch();
// We expect the result to be in the first column of the first row
if ( values.isEmpty() || values.get( 0 ).isEmpty() ) {
return 0;
} else {
PolyNumber number = values.get( 0 ).get( 0 ).asNumber();
if ( statement.getMonitoringEvent() != null ) {
StatementEvent eventData = statement.getMonitoringEvent();
if ( context.getStatement().getMonitoringEvent() != null ) {
StatementEvent eventData = context.getStatement().getMonitoringEvent();
eventData.setRowCount( number.longValue() );
}
return number.longValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public static long getNamespaceIdOrDefault( String namespace ) {
transaction.setUseCache( context.isUsesCache() );
attachAnalyzerIfSpecified( context, crud, transaction );

List<ExecutedContext> executedContexts = LanguageManager.getINSTANCE().anyQuery( context.addTransaction( transaction ), context.getStatement() == null ? transaction.createStatement() : context.getStatement() );
List<ExecutedContext> executedContexts = LanguageManager.getINSTANCE().anyQuery( context.addTransaction( transaction ) );

List<Result<?, ?>> results = new ArrayList<>();
TriFunction<ExecutedContext, UIRequest, Statement, ResultBuilder<?, ?, ?, ?>> builder = REGISTER.get( context.getLanguage() );
Expand Down Expand Up @@ -216,7 +216,7 @@ public static PolyGraph getGraph( String namespace, TransactionManager manager,
.namespaceId( getNamespaceIdOrDefault( namespace ) )
.transactionManager( manager )
.informationTarget( i -> i.setSession( session ) )
.build(), transaction.createStatement() ).get( 0 );
.build(), transaction ).get( 0 );

if ( context.getException().isPresent() ) {
return new PolyGraph( PolyMap.of( new HashMap<>() ), PolyMap.of( new HashMap<>() ) );
Expand Down

0 comments on commit 94d72cb

Please sign in to comment.