3 Commits

Author SHA1 Message Date
beat4ocean
36b7f1f8f6 Merge 19b402cc92 into b7369abcca 2025-03-11 23:20:47 +08:00
jerryjzhang
b7369abcca [improvement][docker]Facilitate database configuration when running with docker.
Some checks are pending
supersonic CentOS CI / build (21) (push) Waiting to run
supersonic mac CI / build (21) (push) Waiting to run
supersonic ubuntu CI / build (21) (push) Waiting to run
supersonic windows CI / build (21) (push) Waiting to run
2025-03-11 23:14:40 +08:00
beat4ocean
19b402cc92 [fix][headless] Fix issue filterSql is not working. 2025-03-11 22:52:19 +08:00
15 changed files with 67 additions and 44 deletions

View File

@@ -0,0 +1,5 @@
#!/usr/bin/env sh
export SUPERSONIC_VERSION=latest
docker-compose -f docker-compose.yml -p supersonic up

View File

@@ -0,0 +1,23 @@
#!/usr/bin/env sh
export SUPERSONIC_VERSION=latest
#### Set below DB configs to connect to your own database
# Supported DB_TYPE: h2, mysql, postgres
export S2_DB_TYPE=h2
export S2_DB_HOST=
export S2_DB_PORT=
export S2_DB_USER=
export S2_DB_PASSWORD=
export S2_DB_DATABASE=
docker run --rm -it -d \
--name supersonic_standalone \
-p 9080:9080 \
-e S2_DB_TYPE=${S2_DB_TYPE} \
-e S2_DB_HOST=${S2_DB_HOST} \
-e S2_DB_PORT=${S2_DB_PORT} \
-e S2_DB_USER=${S2_DB_USER} \
-e S2_DB_PASSWORD=${S2_DB_PASSWORD} \
-e S2_DB_DATABASE=${S2_DB_DATABASE} \
supersonicbi/supersonic:${SUPERSONIC_VERSION}

View File

@@ -1,10 +1,11 @@
#!/usr/bin/env bash
#### Set below DB configs to connect to your own database
# Comment out below exports to config your DB connection
# Supported DB_TYPE: h2, mysql, postgres
export S2_DB_TYPE=h2
export S2_DB_HOST=
export S2_DB_PORT=
export S2_DB_USER=
export S2_DB_PASSWORD=
export S2_DB_DATABASE=
#export S2_DB_TYPE=h2
#export S2_DB_HOST=
#export S2_DB_PORT=
#export S2_DB_USER=
#export S2_DB_PASSWORD=
#export S2_DB_DATABASE=

View File

@@ -27,4 +27,4 @@ WORKDIR /usr/src/app/supersonic-standalone-${SUPERSONIC_VERSION}
EXPOSE 9080
# Command to run the supersonic daemon
RUN chmod +x bin/supersonic-daemon.sh
CMD ["bash", "-c", "bin/supersonic-daemon.sh restart standalone docker && tail -f /dev/null"]
CMD ["bash", "-c", "bin/supersonic-daemon.sh restart standalone ${S2_DB_TYPE} && tail -f /dev/null"]

View File

@@ -2,8 +2,8 @@
# Function to execute the build script
execute_build_script() {
echo "Executing build script: assembly/bin/supersonic-build.sh"
assembly/bin/supersonic-build.sh
echo "Executing build script: sh assembly/bin/supersonic-build.sh"
sh assembly/bin/supersonic-build.sh
}
# Function to build the Docker image

View File

@@ -1,3 +0,0 @@
#!/usr/bin/env bash
SUPERSONIC_VERSION=latest docker-compose -f docker-compose.yml -p supersonic up

View File

@@ -30,10 +30,12 @@ services:
privileged: true
container_name: supersonic_standalone
environment:
DB_HOST: supersonic_postgres
DB_NAME: postgres
DB_USERNAME: supersonic_user
DB_PASSWORD: supersonic_password
S2_DB_TYPE: postgres
S2_DB_HOST: supersonic_postgres
S2_DB_PORT: 5432
S2_DB_DATABASE: postgres
S2_DB_USER: supersonic_user
S2_DB_PASSWORD: supersonic_password
ports:
- "9080:9080"
depends_on:

View File

@@ -24,6 +24,8 @@ public class ModelDetail {
private String tableQuery;
private String filterSql;
private List<Identify> identifiers = Lists.newArrayList();
private List<Dimension> dimensions = Lists.newArrayList();

View File

@@ -19,6 +19,8 @@ public class ModelBuildReq {
private String sql;
private String filterSql;
private String catalog;
private String db;

View File

@@ -40,11 +40,23 @@ public class DataModelNode extends SemanticNode {
.equalsIgnoreCase(EngineType.POSTGRESQL.getName())) {
String fullTableName = String.join(".public.",
dataModel.getModelDetail().getTableQuery().split("\\."));
sqlTable = "select * from " + fullTableName;
sqlTable = "SELECT * FROM " + fullTableName;
} else {
sqlTable = "select * from " + dataModel.getModelDetail().getTableQuery();
sqlTable = "SELECT * FROM " + dataModel.getModelDetail().getTableQuery();
}
}
// String filterSql = dataModel.getFilterSql();
String filterSql = dataModel.getModelDetail().getFilterSql();
if (filterSql != null && !filterSql.isEmpty()) {
boolean sqlContainWhere = sqlTable.toUpperCase().matches("(?s).*\\bWHERE\\b.*");
if (sqlContainWhere) {
sqlTable = String.format("%s AND %s", sqlTable, filterSql);
} else {
sqlTable = String.format("%s WHERE %s", sqlTable, filterSql);
}
}
if (sqlTable.isEmpty()) {
throw new Exception("DataModelNode build error [tableSqlNode not found]");
}

View File

@@ -36,6 +36,7 @@ public class ModelYamlManager {
} else {
dataModelYamlTpl.setTableQuery(modelDetail.getTableQuery());
}
dataModelYamlTpl.setFilterSql(modelDetail.getFilterSql());
dataModelYamlTpl.setFields(modelResp.getModelDetail().getFields());
dataModelYamlTpl.setId(modelResp.getId());
return dataModelYamlTpl;

View File

@@ -97,6 +97,7 @@ public class SemanticSchemaManager {
modelDetail.setDbType(d.getType());
modelDetail.setSqlQuery(d.getSqlQuery());
modelDetail.setTableQuery(d.getTableQuery());
modelDetail.setFilterSql(d.getFilterSql());
modelDetail.getIdentifiers().addAll(getIdentify(d.getIdentifiers()));
modelDetail.getMeasures().addAll(getMeasureParams(d.getMeasures()));
modelDetail.getDimensions().addAll(getDimensions(d.getDimensions()));

View File

@@ -21,6 +21,8 @@ public class DataModelYamlTpl {
private String tableQuery;
private String filterSql;
private List<IdentifyYamlTpl> identifiers;
private List<DimensionYamlTpl> dimensions;

View File

@@ -179,6 +179,7 @@ public class ModelConverter {
}
}
modelDetail.setFields(fields);
modelDetail.setFilterSql(modelBuildReq.getFilterSql());
modelReq.setModelDetail(modelDetail);
return modelReq;
}

View File

@@ -1,26 +0,0 @@
spring:
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://${DB_HOST}:${DB_PORT:5432}/${DB_NAME}?stringtype=unspecified
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
sql:
init:
continue-on-error: true
mode: always
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
schema-locations: classpath:db/schema-postgres.sql,classpath:db/schema-postgres-demo.sql
data-locations: classpath:db/data-postgres.sql,classpath:db/data-postgres-demo.sql
s2:
embedding:
store:
provider: PGVECTOR
base:
url: ${DB_HOST}
port: ${DB_PORT:5432}
databaseName: ${DB_NAME}
user: ${DB_USERNAME}
password: ${DB_PASSWORD}
dimension: 512