Skip to content

Commit

Permalink
separated create source and store, adjusted some PolyValues
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed Apr 2, 2024
1 parent 55153a3 commit 48b5066
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 99 deletions.
12 changes: 2 additions & 10 deletions core/src/main/java/org/polypheny/db/adapter/AdapterManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public ImmutableMap<String, DataSource<?>> getSources() {
}


public Adapter<?> addAdapter( String adapterName, String uniqueName, long defaultNamespace, AdapterType adapterType, DeployMode mode, Map<String, String> settings ) {
public Adapter<?> addAdapter( String adapterName, String uniqueName, AdapterType adapterType, DeployMode mode, Map<String, String> settings ) {
uniqueName = uniqueName.toLowerCase();
if ( getAdapters().containsKey( uniqueName ) ) {
throw new GenericRuntimeException( "There is already an adapter with this unique name" );
Expand All @@ -181,7 +181,7 @@ public Adapter<?> addAdapter( String adapterName, String uniqueName, long defaul

AdapterTemplate adapterTemplate = AdapterTemplate.fromString( adapterName, adapterType );

long adapterId = Catalog.getInstance().createAdapter( uniqueName, adapterName, defaultNamespace, adapterType, settings, mode );
long adapterId = Catalog.getInstance().createAdapter( uniqueName, adapterName, adapterType, settings, mode );
try {
Adapter<?> adapter = adapterTemplate.getDeployer().get( adapterId, uniqueName, settings );
adapterByName.put( adapter.getUniqueName(), adapter );
Expand Down Expand Up @@ -263,12 +263,4 @@ public interface Function4<P1, P2, P3, R> {

}


@FunctionalInterface
public interface Function5<P1, P2, P3, P4, R> {

R get( P1 p1, P2 p2, P3 p3, P4 p4 );

}

}
3 changes: 1 addition & 2 deletions core/src/main/java/org/polypheny/db/catalog/Catalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,12 @@ public void removeObserver( PropertyChangeListener listener ) {
*
* @param uniqueName The unique name of the adapter
* @param clazz The class name of the adapter
* @param defaultNamespace The default namespace of the adapter
* @param type The type of adapter
* @param settings The configuration of the adapter
* @param mode The deploy mode of the adapter
* @return The id of the newly added adapter
*/
public abstract long createAdapter( String uniqueName, String clazz, long defaultNamespace, AdapterType type, Map<String, String> settings, DeployMode mode );
public abstract long createAdapter( String uniqueName, String clazz, AdapterType type, Map<String, String> settings, DeployMode mode );

/**
* Update settings of an adapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public class LogicalAdapter implements PolyObject {
public String adapterTypeName;
@Serialize
public DeployMode mode;
@Serialize
public long defaultNamespace;


public enum AdapterType {STORE, SOURCE}
Expand All @@ -66,16 +64,14 @@ public LogicalAdapter(
@Deserialize("adapterName") @NonNull final String adapterName,
@Deserialize("type") @NonNull final AdapterType adapterType,
@Deserialize("mode") @NotNull final DeployMode mode,
@Deserialize("settings") @NonNull final Map<String, String> settings,
@Deserialize("defaultNamespace") final long defaultNamespace ) {
@Deserialize("settings") @NonNull final Map<String, String> settings ) {
this.id = id;
this.uniqueName = uniqueName;
this.adapterName = adapterName;
this.type = adapterType;
this.settings = new HashMap<>( settings );
this.adapterTypeName = getAdapterName();
this.mode = mode;
this.defaultNamespace = defaultNamespace;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,9 @@ public void dropNamespace( long id ) {


@Override
public long createAdapter( String uniqueName, String clazz, long defaultNamespace, AdapterType type, Map<String, String> settings, DeployMode mode ) {
public long createAdapter( String uniqueName, String clazz, AdapterType type, Map<String, String> settings, DeployMode mode ) {
long id = idBuilder.getNewAdapterId();
adapters.put( id, new LogicalAdapter( id, uniqueName, clazz, type, mode, settings, defaultNamespace ) );
adapters.put( id, new LogicalAdapter( id, uniqueName, clazz, type, mode, settings ) );
change();
return id;
}
Expand Down
27 changes: 20 additions & 7 deletions core/src/main/java/org/polypheny/db/ddl/DdlManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,29 @@ public static DdlManager getInstance() {
public abstract long createNamespace( String name, DataModel type, boolean ifNotExists, boolean replace, Statement statement );

/**
* Adds a new adapter (data store or data source)
* Adds a new data store(adapter)
*
* @param uniqueName unique name of the newly created adapter
* @param adapterName name of adapter, which is used to create the adapter
* @param defaultNamespace the default namespace for the adapter
* @param adapterType the specific {@link AdapterType} for the adapter to create
* @param config configuration for the adapter
* @param uniqueName unique name of the newly created store
* @param adapterName name of store, which is used to create the store
* @param adapterType the specific {@link AdapterType} for the store to create
* @param config configuration for the store
* @param mode the deploy mode
*/
public abstract void createAdapter( String uniqueName, String adapterName, long defaultNamespace, AdapterType adapterType, Map<String, String> config, DeployMode mode );
public abstract void createStore( String uniqueName, String adapterName, AdapterType adapterType, Map<String, String> config, DeployMode mode );


/**
* Adds a new data source(adapter)
*
* @param uniqueName unique name of the newly created source
* @param adapterName name of source, which is used to create the source
* @param namespace the target namespace for the adapter
* @param adapterType the specific {@link AdapterType} for the source to create
* @param config configuration for the source
* @param mode the deploy mode
*/
public abstract void createSource( String uniqueName, String adapterName, long namespace, AdapterType adapterType, Map<String, String> config, DeployMode mode );


/**
* Drop an adapter
Expand Down
18 changes: 9 additions & 9 deletions core/src/main/java/org/polypheny/db/type/entity/PolyBoolean.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
import lombok.Value;
import org.apache.calcite.linq4j.tree.Expression;
import org.apache.calcite.linq4j.tree.Expressions;
import org.apache.commons.lang3.NotImplementedException;
import org.apache.commons.lang3.ObjectUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.polypheny.db.catalog.exceptions.GenericRuntimeException;
import org.polypheny.db.type.PolySerializable;
import org.polypheny.db.type.PolyType;

Expand Down Expand Up @@ -95,18 +95,18 @@ public Object toJava() {
}


public static PolyBoolean convert( Object value ) {
public static PolyBoolean convert( @Nullable PolyValue value ) {
if ( value == null ) {
return null;
}
if ( value instanceof PolyValue poly ) {
if ( poly.isBoolean() ) {
return poly.asBoolean();
} else if ( poly.isNumber() ) {
return poly.asBoolean();
}

if ( value.isBoolean() ) {
return value.asBoolean();
} else if ( value.isNumber() ) {
return value.asBoolean();
}
throw new NotImplementedException( "convert value to Boolean" );

throw new GenericRuntimeException( getConvertError( value, PolyBoolean.class ) );
}


Expand Down
20 changes: 9 additions & 11 deletions core/src/main/java/org/polypheny/db/type/entity/PolyString.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
import lombok.Value;
import org.apache.calcite.linq4j.tree.Expression;
import org.apache.calcite.linq4j.tree.Expressions;
import org.apache.commons.lang3.NotImplementedException;
import org.apache.commons.lang3.ObjectUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.polypheny.db.catalog.exceptions.GenericRuntimeException;
import org.polypheny.db.type.PolySerializable;
import org.polypheny.db.type.PolyType;
import org.polypheny.db.util.Util;
Expand Down Expand Up @@ -102,20 +102,18 @@ public static PolyString concat( List<PolyString> strings ) {
}


public static PolyString convert( Object value ) {
public static PolyString convert( @Nullable PolyValue value ) {
if ( value == null ) {
return null;
}
if ( value instanceof PolyValue poly ) {
if ( poly.isString() ) {
return poly.asString();
} else if ( poly.isDocument() ) {
return PolyString.of( poly.asDocument().toJson() );
} else {
return PolyString.of( poly.toJson() );
}

if ( value.isString() ) {
return value.asString();
} else if ( value.isDocument() ) {
return PolyString.of( value.asDocument().toJson() );
}
throw new NotImplementedException( "convert value to string" );

throw new GenericRuntimeException( getConvertError( value, PolyString.class ) );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.calcite.linq4j.tree.Expression;
import org.apache.calcite.linq4j.tree.Expressions;
import org.apache.commons.lang3.NotImplementedException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.polypheny.db.catalog.exceptions.GenericRuntimeException;
import org.polypheny.db.type.PolySerializable;
import org.polypheny.db.type.PolyType;
Expand Down Expand Up @@ -104,21 +104,16 @@ public PolyDocument( Pair<PolyString, PolyValue>... value ) {
}


public static PolyDocument parse( String string ) {
throw new GenericRuntimeException( "error on parsing Document" );
}


public static PolyDocument convert( Object value ) {
public static PolyDocument convert( @Nullable PolyValue value ) {
if ( value == null ) {
return null;
}
if ( value instanceof PolyValue ) {
if ( ((PolyValue) value).isDocument() ) {
return ((PolyValue) value).asDocument();
}

if ( value.isDocument() ) {
return value.asDocument();
}
throw new NotImplementedException( "convert value to Document" );

throw new GenericRuntimeException( getConvertError( value, PolyDocument.class ) );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.polypheny.db.type.entity.PolyValue;
import org.polypheny.db.type.entity.category.PolyNumber;
import org.polypheny.db.type.entity.category.PolyTemporal;
import org.polypheny.db.type.entity.numerical.PolyDouble;
import org.polypheny.db.util.TimeString;

@EqualsAndHashCode(callSuper = true)
Expand Down Expand Up @@ -90,7 +89,7 @@ public static PolyTime convert( @Nullable PolyValue value ) {
return value.asTime();
}

throw new GenericRuntimeException( getConvertError( value, PolyDouble.class ) );
throw new GenericRuntimeException( getConvertError( value, PolyTime.class ) );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.polypheny.db.type.PolyType;
import org.polypheny.db.type.entity.PolyValue;
import org.polypheny.db.type.entity.category.PolyTemporal;
import org.polypheny.db.type.entity.numerical.PolyDouble;
import org.polypheny.db.util.TimestampString;

@Getter
Expand Down Expand Up @@ -160,7 +159,7 @@ public static PolyTimestamp convert( @Nullable PolyValue value ) {
} else if ( value.isTemporal() ) {
return PolyTimestamp.of( value.asTemporal().getMillisSinceEpoch() );
}
throw new GenericRuntimeException( getConvertError( value, PolyDouble.class ) );
throw new GenericRuntimeException( getConvertError( value, PolyTimestamp.class ) );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void dropNamespace( long id ) {


@Override
public long createAdapter( String uniqueName, String clazz, long defaultNamespace, AdapterType type, Map<String, String> settings, DeployMode mode ) {
public long createAdapter( String uniqueName, String clazz, AdapterType type, Map<String, String> settings, DeployMode mode ) {
throw new NotImplementedException();
}

Expand Down
28 changes: 14 additions & 14 deletions dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,17 @@ public long createNamespace( String initialName, DataModel type, boolean ifNotEx


@Override
public void createAdapter( String uniqueName, String adapterName, long defaultNamespace, AdapterType adapterType, Map<String, String> config, DeployMode mode ) {
public void createStore( String uniqueName, String adapterName, AdapterType adapterType, Map<String, String> config, DeployMode mode ) {
uniqueName = uniqueName.toLowerCase();
Adapter<?> adapter = AdapterManager.getInstance().addAdapter( adapterName, uniqueName, defaultNamespace, adapterType, mode, config );

if ( adapter instanceof DataSource<?> ) {
handleSource( (DataSource<?>) adapter, defaultNamespace );
}
Adapter<?> adapter = AdapterManager.getInstance().addAdapter( adapterName, uniqueName, adapterType, mode, config );
}


private void handleSource( DataSource<?> adapter, long defaultNamespace ) {
@Override
public void createSource( String uniqueName, String adapterName, long namespace, AdapterType adapterType, Map<String, String> config, DeployMode mode ) {
uniqueName = uniqueName.toLowerCase();
DataSource<?> adapter = (DataSource<?>) AdapterManager.getInstance().addAdapter( adapterName, uniqueName, adapterType, mode, config );

Map<String, List<ExportedColumn>> exportedColumns;
try {
exportedColumns = adapter.getExportedColumns();
Expand All @@ -228,26 +228,26 @@ private void handleSource( DataSource<?> adapter, long defaultNamespace ) {
for ( Map.Entry<String, List<ExportedColumn>> entry : exportedColumns.entrySet() ) {
// Make sure the table name is unique
String tableName = entry.getKey();
if ( catalog.getSnapshot().rel().getTable( defaultNamespace, tableName ).isPresent() ) { // apparently we put them all into 1?
if ( catalog.getSnapshot().rel().getTable( namespace, tableName ).isPresent() ) {
int i = 0;
while ( catalog.getSnapshot().rel().getTable( defaultNamespace, tableName + i ).isPresent() ) {
while ( catalog.getSnapshot().rel().getTable( namespace, tableName + i ).isPresent() ) {
i++;
}
tableName += i;
}

LogicalTable logical = catalog.getLogicalRel( defaultNamespace ).addTable( tableName, EntityType.SOURCE, !(adapter).isDataReadOnly() );
LogicalTable logical = catalog.getLogicalRel( namespace ).addTable( tableName, EntityType.SOURCE, !(adapter).isDataReadOnly() );
List<LogicalColumn> columns = new ArrayList<>();

Pair<AllocationPartition, PartitionProperty> partitionProperty = createSinglePartition( logical.namespaceId, logical );

AllocationPlacement placement = catalog.getAllocRel( defaultNamespace ).addPlacement( logical.id, defaultNamespace, adapter.adapterId );
AllocationEntity allocation = catalog.getAllocRel( defaultNamespace ).addAllocation( adapter.getAdapterId(), placement.id, partitionProperty.left.id, logical.id );
AllocationPlacement placement = catalog.getAllocRel( namespace ).addPlacement( logical.id, namespace, adapter.adapterId );
AllocationEntity allocation = catalog.getAllocRel( namespace ).addAllocation( adapter.getAdapterId(), placement.id, partitionProperty.left.id, logical.id );
List<AllocationColumn> aColumns = new ArrayList<>();
int colPos = 1;

for ( ExportedColumn exportedColumn : entry.getValue() ) {
LogicalColumn column = catalog.getLogicalRel( defaultNamespace ).addColumn(
LogicalColumn column = catalog.getLogicalRel( namespace ).addColumn(
exportedColumn.name,
logical.id,
colPos++,
Expand All @@ -260,7 +260,7 @@ private void handleSource( DataSource<?> adapter, long defaultNamespace ) {
exportedColumn.nullable,
Collation.getDefaultCollation() );

AllocationColumn allocationColumn = catalog.getAllocRel( defaultNamespace ).addColumn(
AllocationColumn allocationColumn = catalog.getAllocRel( namespace ).addColumn(
placement.id,
logical.id,
column.id,
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/main/java/org/polypheny/db/ddl/DefaultInserter.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ private static void restoreAdapters( DdlManager ddlManager, Catalog catalog, Run

// Deploy default storeId
Map<String, String> defaultStore = Catalog.snapshot().getAdapterTemplate( Catalog.defaultStore.getAdapterName(), AdapterType.STORE ).orElseThrow().getDefaultSettings();
ddlManager.createAdapter( "hsqldb", Catalog.defaultStore.getAdapterName(), Catalog.defaultNamespaceId, AdapterType.STORE, defaultStore, DeployMode.EMBEDDED );
ddlManager.createStore( "hsqldb", Catalog.defaultStore.getAdapterName(), AdapterType.STORE, defaultStore, DeployMode.EMBEDDED );

if ( mode == RunMode.TEST ) {
return; // source adapters create schema structure, which we do not want for testing
}

// Deploy default CSV view
Map<String, String> defaultSource = Catalog.snapshot().getAdapterTemplate( Catalog.defaultSource.getAdapterName(), AdapterType.SOURCE ).orElseThrow().getDefaultSettings();
ddlManager.createAdapter( "hr", Catalog.defaultSource.getAdapterName(), Catalog.defaultNamespaceId, AdapterType.SOURCE, defaultSource, DeployMode.REMOTE );
ddlManager.createSource( "hr", Catalog.defaultSource.getAdapterName(), Catalog.defaultNamespaceId, AdapterType.SOURCE, defaultSource, DeployMode.REMOTE );


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.polypheny.db.plugins.PolyPlugin;


@SuppressWarnings("unused")
public class GoogleSheetPlugin extends PolyPlugin {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,6 @@

public class MqlMockCatalog extends MockCatalog {

/*@Override
public LogicalNamespace getNamespace( long id ) {
return new LogicalNamespace( 1, "private", 0, 0, "tester", NamespaceType.DOCUMENT, true );
}
@Override
public CatalogUser getUser( long id ) {
return new CatalogUser( 0, "name", "name" );
}*/


@Override
public void change() {

Expand Down
Loading

0 comments on commit 48b5066

Please sign in to comment.