Skip to content

Commit

Permalink
added missing existing transactions and statements for webui updates …
Browse files Browse the repository at this point in the history
…to fix media update and insert, speed up
  • Loading branch information
datomo committed Apr 5, 2024
1 parent 3b27c04 commit 8887779
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import lombok.Getter;
import lombok.Value;
import lombok.experimental.SuperBuilder;
import org.jetbrains.annotations.Nullable;
import org.polypheny.db.algebra.AlgCollation;
import org.polypheny.db.algebra.AlgNode;
import org.polypheny.db.algebra.type.AlgDataType;
Expand Down Expand Up @@ -215,10 +216,15 @@ public void deleteTable( long tableId ) {


@Override
public void setPrimaryKey( long tableId, Long keyId ) {
tables.put( tableId, tables.get( tableId ).toBuilder().primaryKey( keyId ).build() );
public void setPrimaryKey( long tableId, @Nullable Long keyId ) {
LogicalTable oldTable = tables.get( tableId );
// we temporarily can remove the primary, to clean-up old primaries before adding a new one
tables.put( tableId, oldTable.toBuilder().primaryKey( keyId ).build() );

if ( keyId != null ) {
keys.put( keyId, new LogicalPrimaryKey( keys.get( keyId ) ) );
}

keys.put( keyId, new LogicalPrimaryKey( keys.get( keyId ) ) );
change( CatalogEvent.PRIMARY_KEY_CREATED, tableId, keyId );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static void removeQueryLanguage( String name ) {


public List<ImplementationContext> anyPrepareQuery( QueryContext context, Transaction transaction ) {
return anyPrepareQuery( context, transaction.createStatement() );
return anyPrepareQuery( context, context.getStatement() != null ? context.getStatement() : transaction.createStatement() );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class QueryContext {
// we can have mixed transactions, which have ddls and dmls, as long as we commit instantly for ddls,
// we have to open a new transaction for the next statement, so we need to keep track of all transactions (in theory only the last one is needed)
@Builder.Default
@NonFinal
List<Transaction> transactions = new ArrayList<>();


Expand Down Expand Up @@ -120,8 +121,10 @@ public Optional<Node> getQueryNode() {


public <T extends QueryContext> T addTransaction( Transaction transaction ) {
transactions = new ArrayList<>( transactions );
transactions.add( transaction );
return (T) this;
}


}
11 changes: 3 additions & 8 deletions core/src/main/java/org/polypheny/db/type/entity/PolyLong.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import io.activej.serializer.def.SimpleSerializerDef;
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.Objects;
import lombok.EqualsAndHashCode;
import lombok.Value;
import org.apache.calcite.linq4j.tree.Expression;
import org.apache.calcite.linq4j.tree.Expressions;
Expand All @@ -42,6 +42,7 @@
import org.polypheny.db.type.entity.category.PolyNumber;
import org.polypheny.db.type.entity.numerical.PolyBigDecimal;

@EqualsAndHashCode(callSuper = false)
@Value
public class PolyLong extends PolyNumber {

Expand Down Expand Up @@ -207,15 +208,9 @@ public Object toJava() {
}


@Override
public int hashCode() {
return Objects.hash( super.hashCode(), value );
}


@Override
public String toString() {
return value.toString();
return value == null ? null : value.toString();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ public static PolyString ofNullable( String value ) {

@Override
public @Nullable String toJson() {
return value == null ? JsonToken.VALUE_NULL.asString() : value;
return value == null ? JsonToken.VALUE_NULL.asString() : value.replace( "\"", "\\\"" );
}


public @Nullable String toQuotedJson() {
return value == null ? JsonToken.VALUE_NULL.asString() : "\"" + value + "\"";
return value == null ? JsonToken.VALUE_NULL.asString() : "\"" + value.replace( "\"", "\\\"" ) + "\"";
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import io.activej.serializer.def.SimpleSerializerDef;
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.Objects;
import lombok.EqualsAndHashCode;
import lombok.Value;
import org.apache.calcite.linq4j.tree.Expression;
import org.apache.calcite.linq4j.tree.Expressions;
Expand All @@ -40,6 +40,7 @@
import org.polypheny.db.type.entity.PolyValue;
import org.polypheny.db.type.entity.category.PolyNumber;

@EqualsAndHashCode(callSuper = false)
@Value
public class PolyInteger extends PolyNumber {

Expand Down Expand Up @@ -117,12 +118,6 @@ public Expression asExpression() {
}


@Override
public int hashCode() {
return Objects.hash( super.hashCode(), value );
}


@Override
public int compareTo( @NotNull PolyValue o ) {
if ( !o.isNumber() ) {
Expand Down
11 changes: 10 additions & 1 deletion dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -775,11 +775,20 @@ public void createPrimaryKey( LogicalTable table, List<String> columnNames, Stat

LogicalPrimaryKey oldPk = catalog.getSnapshot().rel().getPrimaryKey( table.primaryKey ).orElse( null );

List<Long> columnIds = new LinkedList<>();
List<Long> columnIds = new ArrayList<>();
for ( String columnName : columnNames ) {
LogicalColumn logicalColumn = catalog.getSnapshot().rel().getColumn( table.id, columnName ).orElseThrow();
columnIds.add( logicalColumn.id );
}

if ( oldPk != null && oldPk.key.fieldIds.containsAll( columnIds ) && columnIds.contains( oldPk.key.fieldIds ) ) {
return;
}

if ( oldPk != null ) {
dropConstraint( table, ConstraintType.PRIMARY.name() );
}

catalog.getLogicalRel( table.namespaceId ).addPrimaryKey( table.id, columnIds );
catalog.getLogicalRel( table.namespaceId ).addConstraint( table.id, ConstraintType.PRIMARY.name(), columnIds, ConstraintType.PRIMARY );

Expand Down
3 changes: 3 additions & 0 deletions webui/src/main/java/org/polypheny/db/webui/Crud.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ RelationalResult getTable( final UIRequest request ) {
QueryContext.builder()
.query( query.toString() )
.language( language )
.transactions( List.of( transaction ) )
.origin( transaction.getOrigin() )
.batch( request.noLimit ? -1 : getPageSize() )
.transactionManager( transactionManager )
Expand Down Expand Up @@ -934,6 +935,8 @@ void updateTuple( final Context ctx ) throws ServletException, IOException {
Result<?, ?> result = LanguageCrud.anyQueryResult(
QueryContext.builder()
.query( query )
.statement( statement )
.transactions( List.of( transaction ) )
.language( language )
.origin( ORIGIN )
.transactionManager( transactionManager )
Expand Down
2 changes: 1 addition & 1 deletion webui/src/main/java/org/polypheny/db/webui/WebSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void onMessage( final WsMessageContext ctx ) {
.language( QueryLanguage.from( "cypher" ) )
.origin( POLYPHENY_UI )
.batch( uiRequest.noLimit ? -1 : crud.getPageSize() )
.namespaceId( namespace == null ? Catalog.defaultNamespaceId : namespace.id )
.namespaceId( namespace.id )
.transactionManager( crud.getTransactionManager() )
.informationTarget( i -> i.setSession( ctx.session ) )
.build(), uiRequest ).get( 0 );
Expand Down

0 comments on commit 8887779

Please sign in to comment.