Skip to content

Commit

Permalink
datacube: cleanup app initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
akphi committed Dec 20, 2024
1 parent 90971b8 commit f2bcf44
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Function;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.PackageableRuntime;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.SectionIndex;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseType;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.Database;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.Schema;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.Table;
Expand All @@ -50,7 +52,6 @@
import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.packageableElement.PackageableElementPtr;
import org.finos.legend.engine.repl.client.Client;
import org.finos.legend.engine.repl.core.legend.LegendInterface;
import org.finos.legend.engine.repl.dataCube.server.model.DataCubeQuery;
import org.finos.legend.engine.repl.dataCube.server.model.DataCubeQueryColumn;
import org.finos.legend.engine.repl.shared.ExecutionHelper;
import org.finos.legend.engine.shared.core.operational.errorManagement.EngineException;
Expand Down Expand Up @@ -103,8 +104,9 @@ public static class REPLServerState
public Long startTime;

private PureModelContextData currentPureModelContextData;
private DataCubeQuery query;
private Map<String, ?> source;
private String query;
private Map<String, ?> queryConfiguration;
private Map<String, ?> querySource;

public REPLServerState(Client client, ObjectMapper objectMapper, PlanExecutor planExecutor, LegendInterface legendInterface)
{
Expand Down Expand Up @@ -172,6 +174,8 @@ else if (fn.parameters.size() == 3)
// NOTE: the ONLY use case we want to support right now is when user uses a single DB with relation store accessor
// with a single connection in a single runtime, no mapping, no join, etc.
// Those cases would be too complex to handle and result in too big of a PMCD to persist.
boolean isLocal = false;
boolean isPersistenceSupported = false;
PureModelContextData model = null;
PackageableRuntime runtime = null;
if (runtimePath != null)
Expand Down Expand Up @@ -216,7 +220,12 @@ else if (fn.parameters.size() == 3)
Connection conn = rt.runtimeValue.connections.get(0).storeConnections.get(0).connection;
if (conn instanceof ConnectionPointer)
{
connection = (PackageableConnection) ListIterate.select(pureModelContextData.getElements(), e -> e.getPath().equals(((ConnectionPointer) conn).connection)).getOnly();
PackageableConnection _connection = (PackageableConnection) ListIterate.select(pureModelContextData.getElements(), e -> e.getPath().equals(((ConnectionPointer) conn).connection)).getOnly();
if (_connection.connectionValue instanceof RelationalDatabaseConnection)
{
connection = _connection;
isLocal = DatabaseType.DuckDB.equals(((RelationalDatabaseConnection) _connection.connectionValue).databaseType);
}
}
}
}
Expand All @@ -232,6 +241,7 @@ else if (fn.parameters.size() == 3)
this.legendInterface.compile(model);
model = this.legendInterface.parse(this.legendInterface.render(model), false);
model = PureModelContextData.newBuilder().withSerializer(model.serializer).withElements(ListIterate.reject(model.getElements(), el -> el instanceof SectionIndex)).build();
isPersistenceSupported = true;
}
catch (Exception e)
{
Expand All @@ -243,17 +253,21 @@ else if (fn.parameters.size() == 3)

Map<String, Object> source = Maps.mutable.empty();
source.put("_type", "repl");
source.put("timestamp", this.startTime);
source.put("query", currentExpression.accept(DEPRECATED_PureGrammarComposerCore.Builder.newInstance().build()));
source.put("runtime", runtimePath);
source.put("mapping", mappingPath);
source.put("columns", columns);
source.put("model", model);
this.source = source;
// some extra analytics metadata which would not be part of the persistent query
source.put("mapping", mappingPath);
source.put("timestamp", this.startTime);
source.put("isLocal", isLocal);
source.put("isPersistenceSupported", isPersistenceSupported);
this.querySource = source;

// -------------------- CONFIGURATION --------------------
this.queryConfiguration = null; // initially, the config is not initialized

// -------------------- QUERY --------------------
DataCubeQuery query = new DataCubeQuery();
query.configuration = null; // initially, the config is not initialized
// NOTE: for this, the initial query is going to be a select all
AppliedFunction partialFn = new AppliedFunction();
partialFn.function = "select";
Expand All @@ -265,8 +279,7 @@ else if (fn.parameters.size() == 3)
return colSpec;
});
partialFn.parameters = Lists.mutable.with(new ClassInstance("colSpecArray", colSpecArray, null));
query.query = partialFn.accept(DEPRECATED_PureGrammarComposerCore.Builder.newInstance().build());
this.query = query;
this.query = partialFn.accept(DEPRECATED_PureGrammarComposerCore.Builder.newInstance().build());
}

public void initializeFromTable(PureModelContextData pureModelContextData)
Expand Down Expand Up @@ -333,14 +346,19 @@ public PureModelContextData getCurrentPureModelContextData()
return data;
}

public DataCubeQuery getQuery()
public String getQuery()
{
return this.query;
}

public Map<String, ?> getSource()
public Map<String, ?> getQueryConfiguration()
{
return this.queryConfiguration;
}

public Map<String, ?> getQuerySource()
{
return this.source;
return this.querySource;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public HttpHandler getHandler(REPLServerState state)
try
{
DataCubeInfrastructureInfo info = new DataCubeInfrastructureInfo();
info.gridClientLicense = System.getProperty("legend.repl.dataCube.gridLicenseKey") == null ? "" : System.getProperty("legend.repl.dataCube.gridLicenseKey");
info.gridClientLicense = System.getProperty("legend.repl.dataCube.gridLicenseKey");
info.queryServerBaseUrl = System.getProperty("legend.repl.dataCube.queryServerBaseUrl");
info.hostedApplicationBaseUrl = System.getProperty("legend.repl.dataCube.hostedApplicationBaseUrl");
info.simpleSampleDataTableName = DataCubeSampleData.TREE.tableName;
info.complexSampleDataTableName = DataCubeSampleData.SPORT.tableName;
handleResponse(exchange, 200, state.objectMapper.writeValueAsString(info), state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,14 @@ public HttpHandler getHandler(REPLServerState state)
{
try
{
DataCubeQuery query = state.getQuery();
Map<String, ?> source = state.getSource();
String query = state.getQuery();
Map<String, ?> configuration = state.getQueryConfiguration();
Map<String, ?> source = state.getQuerySource();
if (query != null)
{
DataCubeGetBaseQueryResult result = new DataCubeGetBaseQueryResult();
result.query = query;
result.configuration = configuration;
result.source = source;
handleResponse(exchange, 200, state.objectMapper.writeValueAsString(result), state);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

public class DataCubeGetBaseQueryResult
{
public DataCubeQuery query;
public String query;
public Map<String, ?> configuration;
public Map<String, ?> source;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
public class DataCubeInfrastructureInfo
{
public String gridClientLicense;
public String queryServerBaseUrl;
public String hostedApplicationBaseUrl;
public String simpleSampleDataTableName;
public String complexSampleDataTableName;
}

This file was deleted.

0 comments on commit f2bcf44

Please sign in to comment.