Skip to content

Commit

Permalink
Feat: CREATE SYNOPSIS ~ AS FILE / TABLE / DEFAULT
Browse files Browse the repository at this point in the history
  • Loading branch information
taewhi committed Mar 28, 2024
1 parent 24bdcf6 commit 830d733
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 12 deletions.
7 changes: 6 additions & 1 deletion traindb-core/src/main/antlr4/traindb/sql/TrainDBSql.g4
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,11 @@ newModelName
;

createSynopsis
: K_CREATE K_SYNOPSIS synopsisName K_FROM K_MODEL modelName K_LIMIT limitSizeClause
: K_CREATE K_SYNOPSIS synopsisName synopsisTypeClause? K_FROM K_MODEL modelName K_LIMIT limitSizeClause
;

synopsisTypeClause
: K_AS ( K_TABLE | K_FILE | K_DEFAULT )
;

limitSizeClause
Expand Down Expand Up @@ -319,6 +323,7 @@ K_AS : A S ;
K_BYPASS : B Y P A S S ;
K_CLASS : C L A S S ;
K_CREATE : C R E A T E ;
K_DEFAULT : D E F A U L T ;
K_DELETE : D E L E T E ;
K_DESC : D E S C ;
K_DESCRIBE : D E S C R I B E ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import traindb.schema.TrainDBPartition;
import traindb.schema.TrainDBSchema;
import traindb.schema.TrainDBTable;
import traindb.sql.TrainDBSqlCommand;
import traindb.sql.TrainDBSqlRunner;
import traindb.task.TaskTracer;
import traindb.util.ZipUtils;
Expand Down Expand Up @@ -618,8 +619,8 @@ private AbstractTrainDBModelRunner createModelRunner(String modeltypeName, Strin
}

@Override
public void createSynopsis(String synopsisName, String modelName,
int limitRows, float limitPercent)
public void createSynopsis(String synopsisName, TrainDBSqlCommand.SynopsisType synopsisType,
String modelName, int limitRows, float limitPercent)
throws Exception {

T_tracer.startTaskTracer("create synopsis " + synopsisName);
Expand Down Expand Up @@ -671,7 +672,11 @@ public void createSynopsis(String synopsisName, String modelName,
runner.generateSynopsis(outputPath, limitRows);
T_tracer.closeTaskTime("SUCCESS");

boolean isExternal = conn.isStandalone();
boolean isExternal = false;
if (synopsisType == TrainDBSqlCommand.SynopsisType.FILE
|| (synopsisType == TrainDBSqlCommand.SynopsisType.DEFAULT && conn.isStandalone())) {
isExternal = true;
}

T_tracer.openTaskTime("create synopsis");
double ratio = (double) limitRows / (double) mModel.getTableRows();
Expand Down
19 changes: 15 additions & 4 deletions traindb-core/src/main/java/traindb/sql/TrainDBSql.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ public static TrainDBListResultSet run(TrainDBSqlCommand command, TrainDBSqlRunn
break;
case CREATE_SYNOPSIS:
TrainDBSqlCreateSynopsis createSynopsis = (TrainDBSqlCreateSynopsis) command;
runner.createSynopsis(createSynopsis.getSynopsisName(), createSynopsis.getModelName(),
createSynopsis.getLimitRows(), createSynopsis.getLimitPercent());
runner.createSynopsis(createSynopsis.getSynopsisName(), createSynopsis.getSynopsisType(),
createSynopsis.getModelName(), createSynopsis.getLimitRows(),
createSynopsis.getLimitPercent());
break;
case DROP_SYNOPSIS:
TrainDBSqlDropSynopsis dropSynopsis = (TrainDBSqlDropSynopsis) command;
Expand Down Expand Up @@ -311,17 +312,27 @@ public void exitDropModel(TrainDBSqlParser.DropModelContext ctx) {
@Override
public void exitCreateSynopsis(TrainDBSqlParser.CreateSynopsisContext ctx) {
String synopsisName = ctx.synopsisName().getText();
TrainDBSqlCommand.SynopsisType synopsisType = TrainDBSqlCommand.SynopsisType.DEFAULT;
if (ctx.synopsisTypeClause() != null) {
if (ctx.synopsisTypeClause().K_TABLE() != null) {
synopsisType = TrainDBSqlCommand.SynopsisType.TABLE;
} else if (ctx.synopsisTypeClause().K_FILE() != null) {
synopsisType = TrainDBSqlCommand.SynopsisType.FILE;
}
}
String modelName = ctx.modelName().getText();
if (ctx.limitSizeClause().limitRows() != null) {
int limitRows = Integer.parseInt(ctx.limitSizeClause().limitRows().getText());
LOG.debug("CREATE SYNOPSIS: synopsis=" + synopsisName + " model=" + modelName
+ " limitRows=" + limitRows);
commands.add(new TrainDBSqlCreateSynopsis(synopsisName, modelName, limitRows, 0));
commands.add(
new TrainDBSqlCreateSynopsis(synopsisName, synopsisType, modelName, limitRows, 0));
} else if (ctx.limitSizeClause().limitPercent() != null) {
float limitPercent = Float.parseFloat(ctx.limitSizeClause().limitPercent().getText());
LOG.debug("CREATE SYNOPSIS: synopsis=" + synopsisName + " model=" + modelName
+ " limitPercent=" + limitPercent);
commands.add(new TrainDBSqlCreateSynopsis(synopsisName, modelName, 0, limitPercent));
commands.add(
new TrainDBSqlCreateSynopsis(synopsisName, synopsisType, modelName, 0, limitPercent));
}
}

Expand Down
6 changes: 6 additions & 0 deletions traindb-core/src/main/java/traindb/sql/TrainDBSqlCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,10 @@ public enum Type {
ANALYZE_SYNOPSIS,
OTHER
}

public enum SynopsisType {
TABLE,
FILE,
DEFAULT
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
class TrainDBSqlCreateSynopsis extends TrainDBSqlCommand {

private final String synopsisName;
private final SynopsisType synopsisType;
private final String modelName;
private final int limitRows;
private final float limitPercent;

TrainDBSqlCreateSynopsis(String synopsisName, String modelName, int limitRows,
float limitPercent) {
TrainDBSqlCreateSynopsis(String synopsisName, SynopsisType synopsisType, String modelName,
int limitRows, float limitPercent) {
this.synopsisName = synopsisName;
this.synopsisType = synopsisType;
this.modelName = modelName;
this.limitRows = limitRows;
this.limitPercent = limitPercent;
Expand All @@ -33,6 +35,10 @@ String getSynopsisName() {
return synopsisName;
}

SynopsisType getSynopsisType() {
return synopsisType;
}

String getModelName() {
return modelName;
}
Expand Down
4 changes: 2 additions & 2 deletions traindb-core/src/main/java/traindb/sql/TrainDBSqlRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ void trainModel(String modeltypeName, String modelName, String schemaName, Strin

void dropModel(String modelName) throws Exception;

void createSynopsis(String synopsisName, String modelName, int limitRows, float limitPercent)
throws Exception;
void createSynopsis(String synopsisName, TrainDBSqlCommand.SynopsisType synopsisType,
String modelName, int limitRows, float limitPercent) throws Exception;

void dropSynopsis(String synopsisName) throws Exception;

Expand Down

0 comments on commit 830d733

Please sign in to comment.