Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.9k
Data export function, add export to specify certain columns#5689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
7ccff6a4a8ee2687e38f96c73808f0158a962f70a77e12a83fa9786519b698bf5afa19File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -82,6 +82,7 @@ | ||||||||||||||
| import com.google.common.collect.Lists; | ||||||||||||||
| import com.google.common.collect.Maps; | ||||||||||||||
| import com.google.common.collect.Sets; | ||||||||||||||
| import com.google.common.base.Splitter; | ||||||||||||||
| import org.apache.commons.lang.StringUtils; | ||||||||||||||
| import org.apache.logging.log4j.LogManager; | ||||||||||||||
| @@ -167,6 +168,10 @@ public enum JobState { | ||||||||||||||
| private OriginStatement origStmt; | ||||||||||||||
| protected Map<String, String> sessionVariables = Maps.newHashMap(); | ||||||||||||||
| private List<String> exportColumns = Lists.newArrayList(); | ||||||||||||||
| private String columns ; | ||||||||||||||
| public ExportJob() { | ||||||||||||||
| this.id = -1; | ||||||||||||||
| this.dbId = -1; | ||||||||||||||
| @@ -182,6 +187,7 @@ public ExportJob() { | ||||||||||||||
| this.exportPath = ""; | ||||||||||||||
| this.columnSeparator = "\t"; | ||||||||||||||
| this.lineDelimiter = "\n"; | ||||||||||||||
| this.columns = ""; | ||||||||||||||
| } | ||||||||||||||
| public ExportJob(long jobId) { | ||||||||||||||
| @@ -211,7 +217,11 @@ public void setJob(ExportStmt stmt) throws UserException { | ||||||||||||||
| this.partitions = stmt.getPartitions(); | ||||||||||||||
| this.exportTable = db.getTable(stmt.getTblName().getTbl()); | ||||||||||||||
| this.columns = stmt.getColumns(); | ||||||||||||||
| if (!Strings.isNullOrEmpty(this.columns)) { | ||||||||||||||
| Splitter split = Splitter.on(',').trimResults().omitEmptyStrings(); | ||||||||||||||
| this.exportColumns = split.splitToList(stmt.getColumns().toLowerCase()); | ||||||||||||||
| } | ||||||||||||||
| exportTable.readLock(); | ||||||||||||||
| try { | ||||||||||||||
| this.dbId = db.getId(); | ||||||||||||||
| @@ -259,10 +269,18 @@ private void registerToDesc() { | ||||||||||||||
| exportTupleDesc.setTable(exportTable); | ||||||||||||||
| exportTupleDesc.setRef(tableRef); | ||||||||||||||
| for (Column col : exportTable.getBaseSchema()) { | ||||||||||||||
| SlotDescriptor slot = desc.addSlotDescriptor(exportTupleDesc); | ||||||||||||||
| slot.setIsMaterialized(true); | ||||||||||||||
| slot.setColumn(col); | ||||||||||||||
| slot.setIsNullable(col.isAllowNull()); | ||||||||||||||
| String colName = col.getName().toLowerCase(); | ||||||||||||||
| if (!this.exportColumns.isEmpty() && this.exportColumns.contains(colName)) { | ||||||||||||||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
| ||||||||||||||
| SlotDescriptor slot = desc.addSlotDescriptor(exportTupleDesc); | ||||||||||||||
| slot.setIsMaterialized(true); | ||||||||||||||
| slot.setColumn(col); | ||||||||||||||
| slot.setIsNullable(col.isAllowNull()); | ||||||||||||||
| } else { | ||||||||||||||
| SlotDescriptor slot = desc.addSlotDescriptor(exportTupleDesc); | ||||||||||||||
| slot.setIsMaterialized(true); | ||||||||||||||
| slot.setColumn(col); | ||||||||||||||
| slot.setIsNullable(col.isAllowNull()); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| desc.computeMemLayout(); | ||||||||||||||
| } | ||||||||||||||
| @@ -447,6 +465,10 @@ private void genCoordinators(List<PlanFragment> fragments, List<ScanNode> nodes) | ||||||||||||||
| LOG.info("create {} coordinators for export job: {}", coordList.size(), id); | ||||||||||||||
| } | ||||||||||||||
| public String getColumns() { | ||||||||||||||
| return columns; | ||||||||||||||
| } | ||||||||||||||
| public long getId() { | ||||||||||||||
| return id; | ||||||||||||||
| } | ||||||||||||||
| @@ -740,7 +762,11 @@ public void readFields(DataInput in) throws IOException { | ||||||||||||||
| this.properties.put(propertyKey, propertyValue); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| this.columns = this.properties.get(LoadStmt.KEY_IN_PARAM_COLUMNS); | ||||||||||||||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
| ||||||||||||||
| if (!Strings.isNullOrEmpty(this.columns)) { | ||||||||||||||
| Splitter split = Splitter.on(',').trimResults().omitEmptyStrings(); | ||||||||||||||
| this.exportColumns = split.splitToList(this.columns); | ||||||||||||||
| } | ||||||||||||||
| boolean hasPartition = in.readBoolean(); | ||||||||||||||
| if (hasPartition) { | ||||||||||||||
| partitions = Lists.newArrayList(); | ||||||||||||||
| @@ -782,7 +808,7 @@ public void readFields(DataInput in) throws IOException { | ||||||||||||||
| String value = Text.readString(in); | ||||||||||||||
| sessionVariables.put(key, value); | ||||||||||||||
| } | ||||||||||||||
| if (origStmt.originStmt.isEmpty()) { | ||||||||||||||
| return; | ||||||||||||||
| } | ||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以把英文注释也加一下~