Skip to content

Commit

Permalink
Make views serialize and deserialize correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
gartens committed Dec 20, 2024
1 parent c4c1269 commit 368510b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 12 deletions.
2 changes: 2 additions & 0 deletions core/src/main/java/org/polypheny/db/algebra/AlgCollation.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
package org.polypheny.db.algebra;


import io.activej.serializer.annotations.SerializeClass;
import java.io.Serializable;
import java.util.List;
import org.polypheny.db.plan.AlgMultipleTrait;
Expand All @@ -44,6 +45,7 @@
* <p>
* An ordering consists of a list of one or more column ordinals and the direction of the ordering.
*/
@SerializeClass(subclasses = { AlgCollationImpl.class })
public interface AlgCollation extends AlgMultipleTrait<AlgCollationTraitDef>, Serializable {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.UnmodifiableIterator;
import io.activej.serializer.annotations.Deserialize;
import io.activej.serializer.annotations.Serialize;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Nonnull;
import lombok.Getter;
import org.polypheny.db.plan.AlgMultipleTrait;
Expand All @@ -53,11 +56,12 @@
@Getter
public class AlgCollationImpl implements AlgCollation {

private final ImmutableList<AlgFieldCollation> fieldCollations;
@Serialize
public final ImmutableList<AlgFieldCollation> fieldCollations;


protected AlgCollationImpl( ImmutableList<AlgFieldCollation> fieldCollations ) {
this.fieldCollations = fieldCollations;
public AlgCollationImpl( @Deserialize("fieldCollations") List<AlgFieldCollation> fieldCollations ) {
this.fieldCollations = ImmutableList.copyOf( fieldCollations );
Preconditions.checkArgument( Util.isDistinct( AlgCollations.ordinals( fieldCollations ) ), "fields must be distinct" );
}

Expand Down Expand Up @@ -147,6 +151,5 @@ public String toString() {
}
}


}

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
package org.polypheny.db.algebra;


import io.activej.serializer.annotations.Deserialize;
import io.activej.serializer.annotations.Serialize;
import java.io.Serializable;
import java.util.Objects;
import lombok.Getter;
Expand Down Expand Up @@ -177,17 +179,20 @@ public enum NullDirection {
* 0-based index of field being sorted.
*/
@Getter
private final int fieldIndex;
@Serialize
public final int fieldIndex;

/**
* Direction of sorting.
*/
@Getter
@Serialize
public final Direction direction;

/**
* Direction of sorting of nulls.
*/
@Serialize
public final NullDirection nullDirection;


Expand All @@ -210,7 +215,7 @@ public AlgFieldCollation( int fieldIndex, Direction direction ) {
/**
* Creates a field collation.
*/
public AlgFieldCollation( int fieldIndex, Direction direction, NullDirection nullDirection ) {
public AlgFieldCollation( @Deserialize("fieldIndex") int fieldIndex, @Deserialize("direction") Direction direction, @Deserialize("nullDirection") NullDirection nullDirection ) {
this.fieldIndex = fieldIndex;
this.direction = Objects.requireNonNull( direction );
this.nullDirection = Objects.requireNonNull( nullDirection );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,29 @@ public class LogicalMaterializedView extends LogicalView {
public boolean ordered;


public LogicalMaterializedView(
long id,
String name,
long namespaceId,
String query,
AlgCollation algCollation,
Map<Long, List<Long>> underlyingTables,
QueryLanguage language,
MaterializedCriteria materializedCriteria,
boolean ordered
) {
this( id, name, namespaceId, query, algCollation, underlyingTables, language.serializedName(), materializedCriteria, ordered );
}


public LogicalMaterializedView(
@Deserialize("id") long id,
@Deserialize("name") String name,
@Deserialize("namespaceId") long namespaceId,
@Deserialize("entityType") String query,
@Deserialize("query") String query,
@Deserialize("algCollation") AlgCollation algCollation,
@Deserialize("underlyingTables") Map<Long, List<Long>> underlyingTables,
@Deserialize("language") QueryLanguage language,
@Deserialize("sLanguage") String sLanguage,
@Deserialize("materializedCriteria") MaterializedCriteria materializedCriteria,
@Deserialize("ordered") boolean ordered
) {
Expand All @@ -63,7 +78,7 @@ public LogicalMaterializedView(
query,
algCollation,
underlyingTables,
language );
sLanguage );

Map<Long, ImmutableList<Long>> map = new HashMap<>();
for ( Entry<Long, List<Long>> e : underlyingTables.entrySet() ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,27 @@ public class LogicalView extends LogicalTable {
@Serialize
public ImmutableMap<Long, List<Long>> underlyingTables;
@Serialize
public String sLanguage;
public QueryLanguage language;
@Serialize
public AlgCollation algCollation;
@Serialize
public String query;


public LogicalView(
long id,
String name,
long namespaceId,
EntityType entityType,
String query,
AlgCollation algCollation,
Map<Long, List<Long>> underlyingTables,
QueryLanguage language ) {
this( id, name, namespaceId, entityType, query, algCollation, underlyingTables, language.serializedName() );
}


public LogicalView(
@Deserialize("id") long id,
@Deserialize("name") String name,
Expand All @@ -66,7 +80,7 @@ public LogicalView(
@Deserialize("query") String query,
@Deserialize("algCollation") AlgCollation algCollation,
@Deserialize("underlyingTables") Map<Long, List<Long>> underlyingTables,
@Deserialize("language") QueryLanguage language ) {
@Deserialize("sLanguage") String sLanguage ) {
super(
id,
name,
Expand All @@ -77,7 +91,8 @@ public LogicalView(
this.query = query;
this.algCollation = algCollation;
this.underlyingTables = ImmutableMap.copyOf( underlyingTables );
this.language = language;
this.sLanguage = sLanguage;
this.language = QueryLanguage.from( sLanguage );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.activej.serializer.BinarySerializer;
import io.activej.serializer.annotations.Deserialize;
import io.activej.serializer.annotations.Serialize;
import io.activej.serializer.annotations.SerializeClass;
import java.beans.PropertyChangeSupport;
import java.sql.Timestamp;
import java.util.HashSet;
Expand Down Expand Up @@ -80,7 +81,7 @@ public class RelationalCatalog implements PolySerializable, LogicalRelationalCat

@Serialize
@JsonProperty
public Map<Long, LogicalTable> tables;
public Map<Long, @SerializeClass(subclasses = { LogicalView.class, LogicalTable.class, LogicalMaterializedView.class }) LogicalTable> tables;

@Serialize
@JsonProperty
Expand Down

0 comments on commit 368510b

Please sign in to comment.