Skip to content

Commit

Permalink
fixes for ddls of document
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo authored and danylokravchenko committed Dec 2, 2023
1 parent c80f55f commit eb02482
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
10 changes: 6 additions & 4 deletions dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<EntityType> entityTypes = new ArrayList<>();
Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -2002,6 +2002,8 @@ private void buildNamespace( long namespaceId, LogicalTable logical, Adapter<?>
public void createCollection( long namespaceId, String name, boolean ifNotExists, List<DataStore<?>> stores, PlacementType placementType, Statement statement ) {
String adjustedName = adjustNameIfNeeded( name, namespaceId );

checkModelLangCompatibility( DataModel.DOCUMENT, namespaceId );

if ( assertEntityExists( namespaceId, adjustedName, ifNotExists ) ) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ private static List<ParsedQueryContext> anyQuerySplitter( QueryContext context )
if ( queryNode.getEntity() == null ) {
continue;
}
Optional<LogicalCollection> collection = snapshot.doc().getCollection( query.getNamespaceId(), queryNode.getEntity() );
Optional<LogicalCollection> 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() ) );
}
}
}
Expand Down
1 change: 1 addition & 0 deletions webui/src/main/java/org/polypheny/db/webui/WebSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends Result<?, ?>> anyQueryResult( QueryContext context, UIRequest request ) {
Transaction transaction = context.getTransactionManager().startTransaction( context.getUserId(), Catalog.defaultNamespaceId, context.isAnalysed(), context.getOrigin() );
transaction.setUseCache( context.isUsesCache() );
Expand Down Expand Up @@ -364,6 +371,7 @@ public static List<String[]> computeResultData( final List<List<PolyValue>> 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 );

Expand All @@ -377,7 +385,7 @@ public static List<String[]> computeResultData( final List<List<PolyValue>> rows

public static ResultBuilder<?, ?, ?, ?> getDocResult( ExecutedContext context, UIRequest request, Statement statement ) {
ResultIterator iterator = context.getIterator();
List<List<PolyValue>> data = iterator.getNextBatch();
List<List<PolyValue>> data = new ArrayList<>();

try {
for ( int i = 0; i < request.currentPage; i++ ) {
Expand All @@ -397,6 +405,7 @@ public static List<String[]> computeResultData( final List<List<PolyValue>> 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 );
Expand Down

0 comments on commit eb02482

Please sign in to comment.