From bbaf695454214bd46bdb157c0f8d7c0f6b871ce3 Mon Sep 17 00:00:00 2001 From: datomo Date: Thu, 30 Nov 2023 23:59:58 +0100 Subject: [PATCH] fixes for ddls of document --- .../java/org/polypheny/db/ddl/DdlManagerImpl.java | 10 ++++++---- .../polypheny/db/languages/MongoLanguagePlugin.java | 4 ++-- .../main/java/org/polypheny/db/webui/WebSocket.java | 1 + .../org/polypheny/db/webui/crud/LanguageCrud.java | 11 ++++++++++- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java b/dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java index 73371deef3..e60024398a 100644 --- a/dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java +++ b/dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java @@ -1528,7 +1528,7 @@ public void createView( String viewName, long namespaceId, AlgNode algNode, AlgC findUnderlyingTablesOfView( algNode, underlyingTables, fieldList ); // add check if underlying table is of model document -> mql, relational -> sql - underlyingTables.keySet().forEach( tableId -> checkModelLangCompatibility( language, namespaceId ) ); + underlyingTables.keySet().forEach( tableId -> checkModelLangCompatibility( language.getDataModel(), namespaceId ) ); LogicalView view = catalog.getLogicalRel( namespaceId ).addView( viewName, @@ -1593,7 +1593,7 @@ public void createMaterializedView( String viewName, long namespaceId, AlgRoot a LogicalRelSnapshot relSnapshot = snapshot.rel(); // add check if underlying table is of model document -> mql, relational -> sql - underlying.keySet().forEach( tableId -> checkModelLangCompatibility( language, namespaceId ) ); + underlying.keySet().forEach( tableId -> checkModelLangCompatibility( language.getDataModel(), namespaceId ) ); if ( materializedCriteria.getCriteriaType() == CriteriaType.UPDATE ) { List entityTypes = new ArrayList<>(); @@ -1646,9 +1646,9 @@ public void createMaterializedView( String viewName, long namespaceId, AlgRoot a } - private void checkModelLangCompatibility( QueryLanguage language, long namespaceId ) { + private void checkModelLangCompatibility( DataModel model, long namespaceId ) { LogicalNamespace namespace = catalog.getSnapshot().getNamespace( namespaceId ).orElseThrow(); - if ( namespace.dataModel != language.getDataModel() ) { + if ( namespace.dataModel != model ) { throw new GenericRuntimeException( "The used language cannot execute schema changing queries on this entity with the data model %s.", namespace.getDataModel() ); @@ -2001,6 +2001,8 @@ private void buildNamespace( long namespaceId, LogicalTable logical, Adapter public void createCollection( long namespaceId, String name, boolean ifNotExists, List> stores, PlacementType placementType, Statement statement ) { String adjustedName = adjustNameIfNeeded( name, namespaceId ); + checkModelLangCompatibility( DataModel.DOCUMENT, namespaceId ); + if ( assertEntityExists( namespaceId, adjustedName, ifNotExists ) ) { return; } diff --git a/plugins/mql-language/src/main/java/org/polypheny/db/languages/MongoLanguagePlugin.java b/plugins/mql-language/src/main/java/org/polypheny/db/languages/MongoLanguagePlugin.java index f06e149d04..d282b11ac0 100644 --- a/plugins/mql-language/src/main/java/org/polypheny/db/languages/MongoLanguagePlugin.java +++ b/plugins/mql-language/src/main/java/org/polypheny/db/languages/MongoLanguagePlugin.java @@ -104,14 +104,14 @@ private static List anyQuerySplitter( QueryContext context ) if ( queryNode.getEntity() == null ) { continue; } - Optional collection = snapshot.doc().getCollection( query.getNamespaceId(), queryNode.getEntity() ); + Optional collection = snapshot.doc().getCollection( context.getNamespaceId(), queryNode.getEntity() ); if ( collection.isEmpty() && !created.contains( Pair.of( context.getNamespaceId(), queryNode.getEntity() ) ) ) { if ( queryNode instanceof MqlCreateCollection || queryNode instanceof MqlCreateView ) { // entity was created during this query created.add( Pair.of( context.getNamespaceId(), queryNode.getEntity() ) ); } else { // we have to create this query manually - toCreate.add( 0, Pair.of( query.getNamespaceId(), queryNode.getEntity() ) ); + toCreate.add( 0, Pair.of( context.getNamespaceId(), queryNode.getEntity() ) ); } } } diff --git a/webui/src/main/java/org/polypheny/db/webui/WebSocket.java b/webui/src/main/java/org/polypheny/db/webui/WebSocket.java index 2f84dc38e7..f292e2bb32 100644 --- a/webui/src/main/java/org/polypheny/db/webui/WebSocket.java +++ b/webui/src/main/java/org/polypheny/db/webui/WebSocket.java @@ -125,6 +125,7 @@ public void onMessage( final WsMessageContext ctx ) { .language( language ) .isAnalysed( queryRequest.analyze ) .usesCache( queryRequest.cache ) + .namespaceId( LanguageCrud.getNamespaceIdOrDefault( queryRequest.namespace ) ) .origin( POLYPHENY_UI ).batch( queryRequest.noLimit ? -1 : crud.getPageSize() ) .transactionManager( crud.getTransactionManager() ) .informationTarget( i -> i.setSession( ctx.session ) ).build(), queryRequest ); 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 b76963402a..6e86280cb1 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 @@ -117,18 +117,25 @@ public static void deleteToResult( QueryLanguage language ) { public static void anyQuery( Context ctx ) { QueryRequest request = ctx.bodyAsClass( QueryRequest.class ); QueryLanguage language = QueryLanguage.from( request.language ); + QueryContext context = QueryContext.builder() .query( request.query ) .language( language ) .isAnalysed( request.analyze ) .usesCache( request.cache ) .origin( "Polypheny-UI" ) + .namespaceId( getNamespaceIdOrDefault( request.namespace ) ) .batch( request.noLimit ? -1 : crud.getPageSize() ) .transactionManager( crud.getTransactionManager() ).build(); ctx.json( anyQueryResult( context, request ) ); } + public static long getNamespaceIdOrDefault( String namespace ) { + return namespace == null ? Catalog.defaultNamespaceId : Catalog.snapshot().getNamespace( namespace ).orElseThrow().id; + } + + public static List> anyQueryResult( QueryContext context, UIRequest request ) { Transaction transaction = context.getTransactionManager().startTransaction( context.getUserId(), Catalog.defaultNamespaceId, context.isAnalysed(), context.getOrigin() ); transaction.setUseCache( context.isUsesCache() ); @@ -364,6 +371,7 @@ public static List computeResultData( final List> rows .query( context.getQuery().getQuery() ) .language( context.getQuery().getLanguage() ) .dataModel( context.getIterator().getImplementation().getDataModel() ) + .affectedTuples( data.size() ) .xid( statement.getTransaction().getXid().toString() ) .namespace( request.namespace ); @@ -377,7 +385,7 @@ public static List computeResultData( final List> rows public static ResultBuilder getDocResult( ExecutedContext context, UIRequest request, Statement statement ) { ResultIterator iterator = context.getIterator(); - List> data = iterator.getNextBatch(); + List> data = new ArrayList<>(); try { for ( int i = 0; i < request.currentPage; i++ ) { @@ -397,6 +405,7 @@ public static List computeResultData( final List> rows .query( context.getQuery().getQuery() ) .language( context.getQuery().getLanguage() ) .hasMore( hasMoreRows ) + .affectedTuples( data.size() ) .xid( statement.getTransaction().getXid().toString() ) .dataModel( context.getIterator().getImplementation().getDataModel() ) .namespace( request.namespace );