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
29 changes: 22 additions & 7 deletions be/src/exec/broker_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,19 +339,20 @@ void BrokerScanner::split_line(const Slice& line) {
delete[] ptr;
} else {
const char* value = line.data;
size_t start = 0; // point to the start pos of next col value.
size_t curpos = 0; // point to the start pos of separator matching sequence.
size_t p1 = 0; // point to the current pos of separator matching sequence.
size_t start = 0; // point to the start pos of next col value.
size_t curpos = 0; // point to the start pos of separator matching sequence.
size_t p1 = 0; // point to the current pos of separator matching sequence.
size_t non_space = 0; // point to the last pos of non_space charactor.

// Separator: AAAA
//
// curpos
// p1
// ▼
// AAAA
// 1000AAAA2000AAAA
// ▲ ▲
// Start │
// p1
// curpos

while (curpos < line.size) {
if (*(value + curpos + p1) != _value_separator[p1]) {
Expand All @@ -362,16 +363,30 @@ void BrokerScanner::split_line(const Slice& line) {
p1++;
if (p1 == _value_separator_length) {
// Match a separator
_split_values.emplace_back(value + start, curpos - start);
non_space = curpos;
// Trim tailing spaces. Be consistent with hive and trino's behavior.
if (_state->trim_tailing_spaces_for_external_table_query()) {
while (non_space > start && *(value + non_space - 1) == ' ') {
non_space--;
}
}
_split_values.emplace_back(value + start, non_space - start);
start = curpos + _value_separator_length;
curpos = start;
p1 = 0;
non_space = 0;
}
}
}

CHECK(curpos == line.size) << curpos << " vs " << line.size;
_split_values.emplace_back(value + start, curpos - start);
non_space = curpos;
if (_state->trim_tailing_spaces_for_external_table_query()) {
while (non_space > start && *(value + non_space - 1) == ' ') {
non_space--;
}
}
_split_values.emplace_back(value + start, non_space - start);
}
}

Expand Down
4 changes: 4 additions & 0 deletions be/src/runtime/runtime_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ class RuntimeState {

bool enable_vectorized_exec() const { return _query_options.enable_vectorized_engine; }

bool trim_tailing_spaces_for_external_table_query() const {
return _query_options.trim_tailing_spaces_for_external_table_query;
}

bool return_object_data_as_binary() const {
return _query_options.return_object_data_as_binary;
}
Expand Down
14 changes: 14 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ public class SessionVariable implements Serializable, Writable {

public static final String ENABLE_PROJECTION = "enable_projection";

public static final String TRIM_TAILING_SPACES_FOR_EXTERNAL_TABLE_QUERY = "trim_tailing_spaces_for_external_table_query";

// session origin value
public Map<Field, String> sessionOriginValue = new HashMap<Field, String>();
// check stmt is or not [select /*+ SET_VAR(...)*/ ...]
Expand Down Expand Up @@ -442,6 +444,9 @@ public class SessionVariable implements Serializable, Writable {
@VariableMgr.VarAttr(name = ENABLE_PROJECTION)
private boolean enableProjection = false;

@VariableMgr.VarAttr(name = TRIM_TAILING_SPACES_FOR_EXTERNAL_TABLE_QUERY, needForward = true)
public boolean trimTailingSpacesForExternalTableQuery = false;

public String getBlockEncryptionMode() {
return blockEncryptionMode;
}
Expand Down Expand Up @@ -906,6 +911,14 @@ public boolean isEnableProjection() {
return enableProjection;
}

public boolean isTrimTailingSpacesForExternalTableQuery() {
return trimTailingSpacesForExternalTableQuery;
}

public void setTrimTailingSpacesForExternalTableQuery(boolean trimTailingSpacesForExternalTableQuery) {
this.trimTailingSpacesForExternalTableQuery = trimTailingSpacesForExternalTableQuery;
}

// Serialize to thrift object
// used for rest api
public TQueryOptions toThrift() {
Expand All @@ -923,6 +936,7 @@ public TQueryOptions toThrift() {
tResult.setCodegenLevel(codegenLevel);
tResult.setEnableVectorizedEngine(enableVectorizedEngine);
tResult.setReturnObjectDataAsBinary(returnObjectDataAsBinary);
tResult.setTrimTailingSpacesForExternalTableQuery(trimTailingSpacesForExternalTableQuery);

tResult.setBatchSize(batchSize);
tResult.setDisableStreamPreaggregations(disableStreamPreaggregations);
Expand Down
3 changes: 3 additions & 0 deletions gensrc/thrift/PaloInternalService.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ struct TQueryOptions {
// show bitmap data in result, if use this in mysql cli may make the terminal
// output corrupted character
43: optional bool return_object_data_as_binary = false

// trim tailing spaces while querying external table and stream load
44: optional bool trim_tailing_spaces_for_external_table_query = false
}


Expand Down