Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ethereum eventdata #459

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c3a4b00
First EventCacheManager draft
Jul 31, 2023
ad384d6
rearranged parts of the caching logic, first part of register schema
datomo Aug 2, 2023
c2bed89
added boilerplate for insert into table
datomo Aug 2, 2023
c07529b
Solve conflicts
Aug 2, 2023
637a685
Add transaction manager extension starter
Aug 4, 2023
3cd9406
Fix (temp) createColumnDefinition in AbstractJdbcStore and remove blo…
Aug 4, 2023
fcbf986
Remove fix in AbstractJdbcStore. Fix with getLengthForType
Aug 5, 2023
5ba4ab7
Fill dynamic parameters with correct information
Aug 7, 2023
dcad654
Refactor getExportedColumn and fix cache type converting issues
Aug 11, 2023
e2f8dcb
Fix caching bug
Aug 11, 2023
7028d1b
Get current status of caching
Aug 13, 2023
f57daec
Add multiple smart contracts handling in cache
Aug 15, 2023
14c0b91
Fix minor adjustments and refinements
Aug 16, 2023
2d4ce62
Add caching route
Aug 18, 2023
85d8527
Update caching logic and fix store value conversions
Aug 28, 2023
661d9d4
Fix original bug concerning blocks and transactions with adding two a…
Aug 28, 2023
f8d198c
Fix bug adding two adapters
Aug 28, 2023
5bacf82
Display error messages and enable multiple caching status for adapters
Aug 29, 2023
71971a8
Add all conversion cases
Aug 29, 2023
d8c3011
Merge branch 'master' of github.com:polypheny/Polypheny-DB into ether…
datomo Sep 1, 2023
d19f16f
added caching rule, not yet working
datomo Sep 1, 2023
f50d191
used router for caching
datomo Sep 1, 2023
0954a1b
hide caching tables and fixed uncached impl
datomo Sep 3, 2023
73f62b4
Clean up code by removing unnecessary elements and logs
Sep 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ dependencies {
exclude group: "com.github.spotbugs"
}

implementation 'com.squareup.okhttp3:okhttp:4.11.0'

// --- Test Compile ---
testImplementation group: "junit", name: "junit", version: junit_version
testImplementation group: "org.hamcrest", name: "hamcrest-core", version: hamcrest_core_version // BSD 3-clause
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/org/polypheny/db/adapter/Adapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public abstract class Adapter {
@Getter
private final String adapterName;

public boolean canCache = false;


@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
Expand Down
13 changes: 13 additions & 0 deletions core/src/main/java/org/polypheny/db/adapter/DataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.pf4j.ExtensionPoint;
import org.polypheny.db.catalog.Catalog.Collation;
import org.polypheny.db.catalog.entity.CatalogAdapter.AdapterType;
import org.polypheny.db.catalog.entity.CatalogGraphDatabase;
import org.polypheny.db.catalog.entity.CatalogGraphPlacement;
import org.polypheny.db.ddl.DdlManager.ColumnTypeInformation;
import org.polypheny.db.ddl.DdlManager.FieldInformation;
import org.polypheny.db.prepare.Context;
import org.polypheny.db.type.PolyType;

Expand Down Expand Up @@ -93,6 +96,16 @@ public String getDisplayType() {
return typeStr;
}


public ColumnTypeInformation toColumnTypeInformation() {
return new ColumnTypeInformation( type, collectionsType, length, scale, dimension, cardinality, nullable );

}

public FieldInformation toFieldInformation(){
return new FieldInformation( name, toColumnTypeInformation(), PolyType.STRING_TYPES.contains( type ) ? Collation.getDefaultCollation() : null, null, physicalPosition );
}

}


Expand Down
5 changes: 4 additions & 1 deletion core/src/main/java/org/polypheny/db/catalog/Catalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@

public abstract class Catalog implements ExtensionPoint {

public static final String HIDDEN_PREFIX = "__hidden__";
public static Adapter defaultStore;
public static Adapter defaultSource;
public static int defaultUserId = 0;
Expand Down Expand Up @@ -490,9 +491,11 @@ protected final boolean isValidIdentifier( final String str ) {
* @param ownerId The if of the owner
* @param entityType The table type
* @param modifiable Whether the content of the table can be modified
* @param cached
* @param hidden
* @return The id of the inserted table
*/
public abstract long addTable( String name, long namespaceId, int ownerId, EntityType entityType, boolean modifiable );
public abstract long addTable( String name, long namespaceId, int ownerId, EntityType entityType, boolean modifiable, boolean cached, boolean hidden );


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class CatalogTable implements CatalogObject, Comparable<CatalogTable> {

@Getter
public final ImmutableList<Long> connectedViews;
public final boolean cached;
public final boolean hidden;


public CatalogTable(
Expand All @@ -66,7 +68,9 @@ public CatalogTable(
final Long primaryKey,
@NonNull final ImmutableList<Integer> dataPlacements,
boolean modifiable,
PartitionProperty partitionProperty ) {
PartitionProperty partitionProperty,
boolean cached,
boolean hidden ) {
this.id = id;
this.name = name;
this.fieldIds = fieldIds;
Expand All @@ -76,6 +80,8 @@ public CatalogTable(
this.entityType = type;
this.primaryKey = primaryKey;
this.modifiable = modifiable;
this.cached = cached;
this.hidden = hidden;

this.partitionProperty = partitionProperty;
this.connectedViews = ImmutableList.of();
Expand All @@ -100,7 +106,9 @@ public CatalogTable(
@NonNull final ImmutableList<Integer> dataPlacements,
boolean modifiable,
PartitionProperty partitionProperty,
ImmutableList<Long> connectedViews ) {
ImmutableList<Long> connectedViews,
boolean cached,
boolean hidden ) {
this.id = id;
this.name = name;
this.fieldIds = fieldIds;
Expand All @@ -116,6 +124,8 @@ public CatalogTable(
this.connectedViews = connectedViews;

this.dataPlacements = ImmutableList.copyOf( dataPlacements );
this.cached = cached;
this.hidden = hidden;

if ( type == EntityType.ENTITY && !modifiable ) {
throw new RuntimeException( "Tables of table type TABLE must be modifiable!" );
Expand Down Expand Up @@ -220,7 +230,7 @@ public CatalogTable getRenamed( String newName ) {
dataPlacements,
modifiable,
partitionProperty,
connectedViews );
connectedViews, false, false );
}


Expand All @@ -237,7 +247,9 @@ public CatalogTable getConnectedViews( ImmutableList<Long> newConnectedViews ) {
dataPlacements,
modifiable,
partitionProperty,
newConnectedViews );
newConnectedViews,
cached,
hidden );
}


Expand All @@ -254,7 +266,9 @@ public CatalogTable getTableWithColumns( ImmutableList<Long> newColumnIds ) {
dataPlacements,
modifiable,
partitionProperty,
connectedViews );
connectedViews,
cached,
hidden );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public CatalogView(
ImmutableMap<Long, ImmutableList<Long>> underlyingTables,
String language ) {
super( id, name, columnIds, schemaId, databaseId, ownerId, entityType, primaryKey, dataPlacements,
modifiable, partitionProperty, connectedViews );
modifiable, partitionProperty, connectedViews, false, false );
this.query = query;
this.algCollation = algCollation;
this.underlyingTables = underlyingTables;
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/org/polypheny/db/ddl/DdlManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,11 @@ public static DdlManager getInstance() {
* @param ifNotExists whether to silently ignore if the table already exists
* @param stores list of data stores on which to create a full placement for this table
* @param placementType which placement type should be used for the initial placements
* @param cached
* @param statement the used statement
* @param hidden
*/
public abstract void createTable( long schemaId, String tableName, List<FieldInformation> columns, List<ConstraintInformation> constraints, boolean ifNotExists, List<DataStore> stores, PlacementType placementType, Statement statement ) throws EntityAlreadyExistsException, ColumnNotExistsException, UnknownPartitionTypeException, UnknownColumnException, PartitionGroupNamesNotUniqueException;
public abstract void createTable( long schemaId, String tableName, List<FieldInformation> columns, List<ConstraintInformation> constraints, boolean ifNotExists, List<DataStore> stores, PlacementType placementType, boolean cached, Statement statement, boolean hidden ) throws EntityAlreadyExistsException, ColumnNotExistsException, UnknownPartitionTypeException, UnknownColumnException, PartitionGroupNamesNotUniqueException;

/**
* Create a new view
Expand Down
97 changes: 84 additions & 13 deletions core/src/main/java/org/polypheny/db/tools/AlgBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,60 @@
package org.polypheny.db.tools;


import static org.polypheny.db.util.Static.RESOURCE;

import com.google.common.base.Preconditions;
import com.google.common.collect.*;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import java.math.BigDecimal;
import java.util.AbstractList;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Deque;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import lombok.Getter;
import org.apache.calcite.linq4j.Ord;
import org.apache.calcite.linq4j.function.Experimental;
import org.bson.BsonValue;
import org.polypheny.db.algebra.*;
import org.polypheny.db.algebra.AlgCollation;
import org.polypheny.db.algebra.AlgCollations;
import org.polypheny.db.algebra.AlgDistribution;
import org.polypheny.db.algebra.AlgFieldCollation;
import org.polypheny.db.algebra.AlgNode;
import org.polypheny.db.algebra.constant.Kind;
import org.polypheny.db.algebra.constant.SemiJoinType;
import org.polypheny.db.algebra.core.*;
import org.polypheny.db.algebra.core.Aggregate;
import org.polypheny.db.algebra.core.AggregateCall;
import org.polypheny.db.algebra.core.AlgFactories;
import org.polypheny.db.algebra.core.AlgFactories.ScanFactory;
import org.polypheny.db.algebra.core.CorrelationId;
import org.polypheny.db.algebra.core.Filter;
import org.polypheny.db.algebra.core.Intersect;
import org.polypheny.db.algebra.core.Join;
import org.polypheny.db.algebra.core.JoinAlgType;
import org.polypheny.db.algebra.core.Match;
import org.polypheny.db.algebra.core.Minus;
import org.polypheny.db.algebra.core.Modify.Operation;
import org.polypheny.db.algebra.core.Project;
import org.polypheny.db.algebra.core.Scan;
import org.polypheny.db.algebra.core.SemiJoin;
import org.polypheny.db.algebra.core.Sort;
import org.polypheny.db.algebra.core.Union;
import org.polypheny.db.algebra.core.Values;
import org.polypheny.db.algebra.fun.AggFunction;
import org.polypheny.db.algebra.logical.document.LogicalDocumentProject;
import org.polypheny.db.algebra.logical.document.LogicalDocumentScan;
Expand All @@ -53,6 +96,7 @@
import org.polypheny.db.algebra.logical.lpg.LogicalLpgProject;
import org.polypheny.db.algebra.logical.lpg.LogicalLpgScan;
import org.polypheny.db.algebra.logical.relational.LogicalFilter;
import org.polypheny.db.algebra.logical.relational.LogicalModify;
import org.polypheny.db.algebra.logical.relational.LogicalProject;
import org.polypheny.db.algebra.metadata.AlgMetadataQuery;
import org.polypheny.db.algebra.operators.OperatorName;
Expand All @@ -63,26 +107,46 @@
import org.polypheny.db.languages.OperatorRegistry;
import org.polypheny.db.languages.QueryLanguage;
import org.polypheny.db.nodes.Operator;
import org.polypheny.db.plan.*;
import org.polypheny.db.rex.*;
import org.polypheny.db.plan.AlgOptCluster;
import org.polypheny.db.plan.AlgOptPredicateList;
import org.polypheny.db.plan.AlgOptSchema;
import org.polypheny.db.plan.AlgOptTable;
import org.polypheny.db.plan.AlgOptUtil;
import org.polypheny.db.plan.Context;
import org.polypheny.db.plan.Contexts;
import org.polypheny.db.prepare.Prepare.CatalogReader;
import org.polypheny.db.rex.RexBuilder;
import org.polypheny.db.rex.RexCall;
import org.polypheny.db.rex.RexCorrelVariable;
import org.polypheny.db.rex.RexExecutor;
import org.polypheny.db.rex.RexInputRef;
import org.polypheny.db.rex.RexLiteral;
import org.polypheny.db.rex.RexNode;
import org.polypheny.db.rex.RexShuttle;
import org.polypheny.db.rex.RexSimplify;
import org.polypheny.db.rex.RexUtil;
import org.polypheny.db.runtime.Hook;
import org.polypheny.db.runtime.PolyCollections.PolyDictionary;
import org.polypheny.db.schema.ModelTrait;
import org.polypheny.db.schema.SchemaPlus;
import org.polypheny.db.schema.graph.PolyNode;
import org.polypheny.db.transaction.Statement;
import org.polypheny.db.type.PolyType;
import org.polypheny.db.util.*;
import org.polypheny.db.util.DateString;
import org.polypheny.db.util.Holder;
import org.polypheny.db.util.ImmutableBitSet;
import org.polypheny.db.util.ImmutableIntList;
import org.polypheny.db.util.ImmutableNullableList;
import org.polypheny.db.util.Litmus;
import org.polypheny.db.util.NlsString;
import org.polypheny.db.util.Pair;
import org.polypheny.db.util.TimeString;
import org.polypheny.db.util.TimestampString;
import org.polypheny.db.util.Util;
import org.polypheny.db.util.ValidatorUtil;
import org.polypheny.db.util.mapping.Mapping;
import org.polypheny.db.util.mapping.Mappings;

import javax.annotation.Nonnull;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

import static org.polypheny.db.util.Static.RESOURCE;


/**
* Builder for relational expressions.
Expand Down Expand Up @@ -2501,6 +2565,13 @@ public void clear() {
}


public AlgBuilder insert( AlgOptTable table ) {
LogicalModify modify = LogicalModify.create( table, (CatalogReader) algOptSchema, stack.pop().alg, Operation.INSERT, null, null, false );
stack.add( new Frame( modify ) );
return this;
}


/**
* Information necessary to create a call to an aggregate function.
*
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/org/polypheny/db/util/BsonUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.InputStream;
import java.io.PushbackInputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
Expand Down Expand Up @@ -354,6 +355,8 @@ private static BsonValue handleBigInt( Object obj ) {

if ( obj instanceof Long ) {
return new BsonInt64( (Long) obj );
} else if ( obj instanceof BigInteger ) {
return new BsonInt64(( (BigInteger) obj ).longValue());
} else {
return new BsonInt64( (Integer) obj );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public CatalogTable getTable( long databaseId, String schemaName, String tableNa


@Override
public long addTable( String name, long namespaceId, int ownerId, EntityType entityType, boolean modifiable ) {
public long addTable( String name, long namespaceId, int ownerId, EntityType entityType, boolean modifiable, boolean cached, boolean hidden ) {
throw new NotImplementedException();
}

Expand Down
11 changes: 7 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 @@ -243,7 +243,8 @@ public void addAdapter( String uniqueName, String adapterName, AdapterType adapt
exportedColumns = ((DataSource) adapter).getExportedColumns();
} catch ( Exception e ) {
AdapterManager.getInstance().removeAdapter( adapter.getAdapterId() );
throw new RuntimeException( "Could not deploy adapter", e );
// throw new RuntimeException( "Could not deploy adapter", e );
throw new RuntimeException( "Could not deploy adapter: " + e.getMessage(), e );
}
// Create table, columns etc.
for ( Map.Entry<String, List<ExportedColumn>> entry : exportedColumns.entrySet() ) {
Expand All @@ -257,7 +258,7 @@ public void addAdapter( String uniqueName, String adapterName, AdapterType adapt
tableName += i;
}

long tableId = catalog.addTable( tableName, 1, 1, EntityType.SOURCE, !((DataSource) adapter).isDataReadOnly() );
long tableId = catalog.addTable( tableName, 1, 1, EntityType.SOURCE, !((DataSource) adapter).isDataReadOnly(), adapter.canCache, false );
List<Long> primaryKeyColIds = new ArrayList<>();
int colPos = 1;
String physicalSchemaName = null;
Expand Down Expand Up @@ -2171,7 +2172,7 @@ private List<Long> getUnderlyingColumns( AlgNode algNode, AlgDataType fieldList


@Override
public void createTable( long schemaId, String name, List<FieldInformation> fields, List<ConstraintInformation> constraints, boolean ifNotExists, List<DataStore> stores, PlacementType placementType, Statement statement ) throws EntityAlreadyExistsException {
public void createTable( long schemaId, String name, List<FieldInformation> fields, List<ConstraintInformation> constraints, boolean ifNotExists, List<DataStore> stores, PlacementType placementType, boolean cached, Statement statement, boolean hidden ) throws EntityAlreadyExistsException {
name = adjustNameIfNeeded( name, schemaId );

try {
Expand Down Expand Up @@ -2209,7 +2210,9 @@ public void createTable( long schemaId, String name, List<FieldInformation> fiel
schemaId,
statement.getPrepareContext().getCurrentUserId(),
EntityType.ENTITY,
true );
true,
cached,
hidden );

// Initially create DataPlacement containers on every store the table should be placed.
stores.forEach( store -> catalog.addDataPlacement( store.getAdapterId(), tableId ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ public void copyPartitionData( Transaction transaction, CatalogAdapter store, Ca
CatalogPrimaryKey primaryKey = Catalog.getInstance().getPrimaryKey( sourceTable.primaryKey );

// Check Lists
List<CatalogColumnPlacement> targetColumnPlacements = new LinkedList<>();
List<CatalogColumnPlacement> targetColumnPlacements = new ArrayList<>();
for ( CatalogColumn catalogColumn : columns ) {
targetColumnPlacements.add( Catalog.getInstance().getColumnPlacement( store.id, catalogColumn.id ) );
}
Expand Down
Loading