Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 19 additions & 3 deletions fe/fe-core/src/main/java/org/apache/doris/analysis/ExportStmt.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
// EXPORT TABLE table_name [PARTITION (name1[, ...])]
// TO 'export_target_path'
// [PROPERTIES("key"="value")]
// BY BROKER 'broker_name' [( $broker_attrs)]
// WITH BROKER 'broker_name' [( $broker_attrs)]
@Getter
public class ExportStmt extends StatementBase {
public static final String PARALLELISM = "parallelism";
Expand All @@ -67,6 +67,7 @@ public class ExportStmt extends StatementBase {
private static final String DEFAULT_COLUMN_SEPARATOR = "\t";
private static final String DEFAULT_LINE_DELIMITER = "\n";
private static final String DEFAULT_PARALLELISM = "1";
private static final Integer DEFAULT_TIMEOUT = 7200;

private static final ImmutableSet<String> PROPERTIES_SET = new ImmutableSet.Builder<String>()
.add(LABEL)
Expand All @@ -76,6 +77,7 @@ public class ExportStmt extends StatementBase {
.add(OutFileClause.PROP_DELETE_EXISTING_FILES)
.add(PropertyAnalyzer.PROPERTIES_COLUMN_SEPARATOR)
.add(PropertyAnalyzer.PROPERTIES_LINE_DELIMITER)
.add(PropertyAnalyzer.PROPERTIES_TIMEOUT)
.add("format")
.build();

Expand All @@ -97,6 +99,8 @@ public class ExportStmt extends StatementBase {

private Integer parallelism;

private Integer timeout;

private String maxFileSize;
private String deleteExistingFiles;
private SessionVariable sessionVariables;
Expand All @@ -118,6 +122,7 @@ public ExportStmt(TableRef tableRef, Expr whereExpr, String path,
this.brokerDesc = brokerDesc;
this.columnSeparator = DEFAULT_COLUMN_SEPARATOR;
this.lineDelimiter = DEFAULT_LINE_DELIMITER;
this.timeout = DEFAULT_TIMEOUT;

Optional<SessionVariable> optionalSessionVariable = Optional.ofNullable(
ConnectContext.get().getSessionVariable());
Expand Down Expand Up @@ -232,8 +237,10 @@ private void setJob() throws UserException {
// set sessions
exportJob.setQualifiedUser(this.qualifiedUser);
exportJob.setUserIdentity(this.userIdentity);
exportJob.setSessionVariables(this.sessionVariables);
exportJob.setTimeoutSecond(this.sessionVariables.getQueryTimeoutS());
SessionVariable clonedSessionVariable = VariableMgr.cloneSessionVariable(Optional.ofNullable(
ConnectContext.get().getSessionVariable()).orElse(VariableMgr.getDefaultSessionVariable()));
exportJob.setSessionVariables(clonedSessionVariable);
exportJob.setTimeoutSecond(this.timeout);

exportJob.setOrigStmt(this.getOrigStmt());
}
Expand Down Expand Up @@ -323,6 +330,15 @@ private void checkProperties(Map<String, String> properties) throws UserExceptio
throw new UserException("The value of parallelism is invalid!");
}

// timeout
String timeoutString = properties.getOrDefault(PropertyAnalyzer.PROPERTIES_TIMEOUT,
String.valueOf(DEFAULT_TIMEOUT));
try {
this.timeout = Integer.parseInt(timeoutString);
} catch (NumberFormatException e) {
throw new UserException("The value of timeout is invalid!");
}

// max_file_size
this.maxFileSize = properties.getOrDefault(OutFileClause.PROP_MAX_FILE_SIZE, "");
this.deleteExistingFiles = properties.getOrDefault(OutFileClause.PROP_DELETE_EXISTING_FILES, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public void cancel() throws JobException {

private AutoCloseConnectContext buildConnectContext() {
ConnectContext connectContext = new ConnectContext();
exportJob.getSessionVariables().setQueryTimeoutS(exportJob.getTimeoutSecond());
connectContext.setSessionVariable(exportJob.getSessionVariables());
connectContext.setEnv(Env.getCurrentEnv());
connectContext.setDatabase(exportJob.getTableName().getDb());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,16 @@
* EXPORT TABLE table_name [PARTITION (name1[, ...])]
* TO 'export_target_path'
* [PROPERTIES("key"="value")]
* BY BROKER 'broker_name' [( $broker_attrs)]
* WITH BROKER 'broker_name' [( $broker_attrs)]
*/
public class ExportCommand extends Command implements ForwardWithSync {
public static final String PARALLELISM = "parallelism";
public static final String LABEL = "label";
private static final String DEFAULT_COLUMN_SEPARATOR = "\t";
private static final String DEFAULT_LINE_DELIMITER = "\n";
private static final String DEFAULT_PARALLELISM = "1";
private static final Integer DEFAULT_TIMEOUT = 7200;

private static final ImmutableSet<String> PROPERTIES_SET = new ImmutableSet.Builder<String>()
.add(LABEL)
.add(PARALLELISM)
Expand All @@ -84,6 +86,7 @@ public class ExportCommand extends Command implements ForwardWithSync {
.add(OutFileClause.PROP_DELETE_EXISTING_FILES)
.add(PropertyAnalyzer.PROPERTIES_COLUMN_SEPARATOR)
.add(PropertyAnalyzer.PROPERTIES_LINE_DELIMITER)
.add(PropertyAnalyzer.PROPERTIES_TIMEOUT)
.add("format")
.build();

Expand Down Expand Up @@ -305,7 +308,18 @@ private ExportJob generateExportJob(ConnectContext ctx, Map<String, String> file
SessionVariable clonedSessionVariable = VariableMgr.cloneSessionVariable(Optional.ofNullable(
ConnectContext.get().getSessionVariable()).orElse(VariableMgr.getDefaultSessionVariable()));
exportJob.setSessionVariables(clonedSessionVariable);
exportJob.setTimeoutSecond(clonedSessionVariable.getQueryTimeoutS());

// set timeoutSecond
int timeoutSecond;
String timeoutString = fileProperties.getOrDefault(PropertyAnalyzer.PROPERTIES_TIMEOUT,
String.valueOf(DEFAULT_TIMEOUT));
try {
timeoutSecond = Integer.parseInt(timeoutString);
} catch (NumberFormatException e) {
throw new UserException("The value of timeout is invalid!");
}

exportJob.setTimeoutSecond(timeoutSecond);

// exportJob generate outfile sql
exportJob.generateOutfileLogicalPlans(RelationUtil.getQualifierName(ctx, this.nameParts));
Expand Down