From 94d72cb728b1a7d4f4797dec66eb985b936a4172 Mon Sep 17 00:00:00 2001 From: datomo Date: Tue, 2 Apr 2024 16:13:46 +0200 Subject: [PATCH] fixes for multiple queries results --- .../polypheny/db/languages/LanguageManager.java | 16 ++++++++++------ .../java/org/polypheny/db/avatica/DbmsMeta.java | 2 +- .../main/java/org/polypheny/db/webui/Crud.java | 15 +++++++-------- .../polypheny/db/webui/crud/LanguageCrud.java | 4 ++-- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/core/src/main/java/org/polypheny/db/languages/LanguageManager.java b/core/src/main/java/org/polypheny/db/languages/LanguageManager.java index c1cbcd8022..a07cce867c 100644 --- a/core/src/main/java/org/polypheny/db/languages/LanguageManager.java +++ b/core/src/main/java/org/polypheny/db/languages/LanguageManager.java @@ -83,9 +83,8 @@ public static void removeQueryLanguage( String name ) { } - public List anyPrepareQuery( QueryContext context, Statement statement ) { - Transaction transaction = statement.getTransaction(); - + public List anyPrepareQuery( QueryContext context, Transaction transaction ) { + Statement statement = transaction.createStatement(); if ( transaction.isAnalyze() ) { context.getInformationTarget().accept( transaction.getQueryAnalyzer() ); } @@ -118,7 +117,11 @@ public List anyPrepareQuery( QueryContext context, Statem Processor processor = context.getLanguage().processorSupplier().get(); List 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() ) { @@ -191,6 +194,7 @@ public List anyPrepareQuery( QueryContext context, Statem implementationContexts.add( ImplementationContext.ofError( e, parsed, statement ) ); return implementationContexts; } + i++; } return implementationContexts; } @@ -218,9 +222,8 @@ private static void cancelTransaction( @Nullable Transaction transaction ) { } - public List anyQuery( QueryContext context, Statement statement ) { - List prepared = anyPrepareQuery( context, statement ); - Transaction transaction = statement.getTransaction(); + public List anyQuery( QueryContext context ) { + List prepared = anyPrepareQuery( context, context.getTransactions().get( context.getTransactions().size() - 1 ) ); List executedContexts = new ArrayList<>(); @@ -231,6 +234,7 @@ public List 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 ); } diff --git a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java index 9d8f8a099e..904f65502c 100644 --- a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java +++ b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java @@ -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 ); diff --git a/webui/src/main/java/org/polypheny/db/webui/Crud.java b/webui/src/main/java/org/polypheny/db/webui/Crud.java index 231a50a4f8..a3017f6015 100644 --- a/webui/src/main/java/org/polypheny/db/webui/Crud.java +++ b/webui/src/main/java/org/polypheny/db/webui/Crud.java @@ -287,7 +287,6 @@ RelationalResult getTable( final UIRequest request ) { TriFunction> builder = LanguageCrud.getToResult( language ); - Statement statement = transaction.createStatement(); ImplementationContext implementationContext = LanguageManager.getINSTANCE().anyPrepareQuery( QueryContext.builder() .query( query.toString() ) @@ -295,8 +294,8 @@ RelationalResult getTable( final UIRequest request ) { .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(); @@ -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> values = context.execute( statement ).getIterator().getNextBatch(); + .transactionManager( transactionManager ).build(), transaction ).get( 0 ); + List> 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(); diff --git a/webui/src/main/java/org/polypheny/db/webui/crud/LanguageCrud.java b/webui/src/main/java/org/polypheny/db/webui/crud/LanguageCrud.java index 2570b43fdb..bf1e429c77 100644 --- a/webui/src/main/java/org/polypheny/db/webui/crud/LanguageCrud.java +++ b/webui/src/main/java/org/polypheny/db/webui/crud/LanguageCrud.java @@ -146,7 +146,7 @@ public static long getNamespaceIdOrDefault( String namespace ) { transaction.setUseCache( context.isUsesCache() ); attachAnalyzerIfSpecified( context, crud, transaction ); - List executedContexts = LanguageManager.getINSTANCE().anyQuery( context.addTransaction( transaction ), context.getStatement() == null ? transaction.createStatement() : context.getStatement() ); + List executedContexts = LanguageManager.getINSTANCE().anyQuery( context.addTransaction( transaction ) ); List> results = new ArrayList<>(); TriFunction> builder = REGISTER.get( context.getLanguage() ); @@ -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<>() ) );