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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.UserException;
import org.apache.doris.common.util.ToSqlContext;

import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
Expand All @@ -46,7 +47,6 @@ public class BaseViewStmt extends DdlStmt {
// Set during analyze
protected final List<Column> finalCols;

protected String originalViewDef;
protected String inlineViewDef;

protected QueryStmt cloneStmt;
Expand Down Expand Up @@ -111,33 +111,26 @@ protected void createColumnAndViewDefs(Analyzer analyzer) throws AnalysisExcepti
}

// format view def string
originalViewDef = viewDefStmt.toSql();

if (cols == null) {
inlineViewDef = originalViewDef;
try (ToSqlContext toSqlContext = ToSqlContext.getOrNewThreadLocalContext()) {
// after being analyzed, the toSql() of SlotRef will output like "<slot 10> col as col",
// we don't need the slot id info, so using ToSqlContext to remove it.
toSqlContext.setNeedSlotRefId(false);
inlineViewDef = viewDefStmt.toSql();
}
return;
}

Analyzer tmpAnalyzer = new Analyzer(analyzer);
List<String> colNames = cols.stream().map(c -> c.getColName()).collect(Collectors.toList());
cloneStmt.substituteSelectList(tmpAnalyzer, colNames);
inlineViewDef = cloneStmt.toSql();

// StringBuilder sb = new StringBuilder();
// sb.append("SELECT ");
// for (int i = 0; i < finalCols.size(); ++i) {
// if (i != 0) {
// sb.append(", ");
// }
// String colRef = viewDefStmt.getColLabels().get(i);
// if (!colRef.startsWith("`")) {
// colRef = "`" + colRef + "`";
// }
// String colAlias = finalCols.get(i).getName();
// sb.append(String.format("`%s`.%s AS `%s`", tableName.getTbl(), colRef, colAlias));
// }
// sb.append(String.format(" FROM (%s) %s", originalViewDef, tableName.getTbl()));
// inlineViewDef = sb.toString();

try (ToSqlContext toSqlContext = ToSqlContext.getOrNewThreadLocalContext()) {
// after being analyzed, the toSql() of SlotRef will output like "<slot 10> col as col",
// we don't need the slot id info, so using ToSqlContext to remove it.
toSqlContext.setNeedSlotRefId(false);
inlineViewDef = cloneStmt.toSql();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.doris.analysis;

import org.apache.doris.catalog.Catalog;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.UserException;
Expand Down Expand Up @@ -54,7 +53,7 @@ public String getComment() {
}

@Override
public void analyze(Analyzer analyzer) throws AnalysisException, UserException {
public void analyze(Analyzer analyzer) throws UserException {
tableName.analyze(analyzer);
viewDefStmt.setNeedToSql(true);

Expand Down
16 changes: 6 additions & 10 deletions fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.io.Text;
import org.apache.doris.common.util.ToSqlContext;
import org.apache.doris.thrift.TExprNode;
import org.apache.doris.thrift.TExprNodeType;
import org.apache.doris.thrift.TSlotRef;
Expand Down Expand Up @@ -164,28 +165,23 @@ public String debugString() {
public String toSqlImpl() {
StringBuilder sb = new StringBuilder();

// if (desc != null) {
// sb.append("[tupleId=");
// sb.append(desc.getParent().getId().asInt());
// sb.append(",SlotId=");
// sb.append(desc.getId().asInt());
// sb.append("]");
// }
if (tblName != null) {
return tblName.toSql() + "." + label + sb.toString();
} else if (label != null) {
return label + sb.toString();
} else if (desc.getSourceExprs() != null) {
if (desc.getId().asInt() != 1) {
sb.append("<slot " + Integer.toString(desc.getId().asInt()) + ">");
if (ToSqlContext.get() == null || ToSqlContext.get().isNeedSlotRefId()) {
if (desc.getId().asInt() != 1) {
sb.append("<slot " + desc.getId().asInt() + ">");
}
}
for (Expr expr : desc.getSourceExprs()) {
sb.append(" ");
sb.append(expr.toSql());
}
return sb.toString();
} else {
return "<slot " + Integer.toString(desc.getId().asInt()) + ">" + sb.toString();
return "<slot " + desc.getId().asInt() + ">" + sb.toString();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public void analyze(Analyzer analyzer) throws AnalysisException, UserException {
*
* @see org.apache.doris.parser.ParseNode#toSql()
*/
@Override
public String toSql() {
return "";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.apache.doris.common.util;

import java.io.Closeable;

/*
* This class is used to control the behavior of certain toSql() methods. The usage is as follows:
*
* try (ToSqlContext toSqlContext =ToSqlContext.getOrNewThreadLocalContext()) {
* toSqlContext.setNeedSlotRefId(false); // set some property
* inlineViewDef = viewDefStmt.toSql(); // call some toSql() methods
* }
*
* This class implements "Closable" interface, and it should be closed right after being used.
* To prevent it from affecting other following logic.
*
*/
public class ToSqlContext implements Closeable {

// Used to control whether to output the slotId in the toSql() method of SlotRef.
private boolean needSlotRefId;

private static ThreadLocal<ToSqlContext> threadLocalInfo = new ThreadLocal<ToSqlContext>();

public ToSqlContext() {

}

public void setNeedSlotRefId(boolean needSlotRefId) {
this.needSlotRefId = needSlotRefId;
}

public boolean isNeedSlotRefId() {
return needSlotRefId;
}

public static ToSqlContext get() {
return threadLocalInfo.get();
}

public static ToSqlContext getOrNewThreadLocalContext() {
ToSqlContext toSqlContext = threadLocalInfo.get();
if (toSqlContext == null) {
toSqlContext = new ToSqlContext();
threadLocalInfo.set(toSqlContext);
}
return toSqlContext;
}

@Override
public void close() {
threadLocalInfo.remove();
}
}
9 changes: 9 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/load/Load.java
Original file line number Diff line number Diff line change
Expand Up @@ -3024,6 +3024,15 @@ private boolean processCancelled(LoadJob job, CancelType cancelType, String msg,
// the transaction may already be aborted due to timeout by transaction manager.
// just print a log and continue to cancel the job.
LOG.info("transaction not found when try to abort it: {}", e.getTransactionId());
} catch (AnalysisException e) {
// This is because the database has been dropped, so dbTransactionMgr can not be found.
// In this case, just continue to cancel the load.
if (!e.getMessage().contains("does not exist")) {
if (failedMsg != null) {
failedMsg.add("Abort transaction failed: " + e.getMessage());
}
return false;
}
} catch (Exception e) {
LOG.info("errors while abort transaction", e);
if (failedMsg != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.doris.qe.cache;

import com.google.common.collect.Lists;
import org.apache.doris.common.Status;
import org.apache.doris.common.util.DebugUtil;
import org.apache.doris.proto.PCacheParam;
Expand All @@ -29,6 +28,9 @@
import org.apache.doris.proto.PUpdateCacheRequest;
import org.apache.doris.qe.RowBatch;
import org.apache.doris.thrift.TResultBatch;

import com.google.common.collect.Lists;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -133,12 +135,10 @@ public static class UpdateCacheRequest extends PUpdateCacheRequest {
public int value_count;
public int row_count;
public int data_size;
private String sqlStr;
private List<CacheValue> valueList;

public UpdateCacheRequest(String sqlStr) {
this.sqlStr = sqlStr;
this.sql_key = getMd5(this.sqlStr);
this.sql_key = getMd5(sqlStr);
this.valueList = Lists.newArrayList();
value_count = 0;
row_count = 0;
Expand Down Expand Up @@ -176,12 +176,10 @@ public void debug() {


public static class FetchCacheRequest extends PFetchCacheRequest {
private String sqlStr;
private List<CacheParam> paramList;

public FetchCacheRequest(String sqlStr) {
this.sqlStr = sqlStr;
this.sql_key = getMd5(this.sqlStr);
this.sql_key = getMd5(sqlStr);
this.paramList = Lists.newArrayList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.doris.qe.cache;

import com.google.common.collect.Lists;
import org.apache.doris.analysis.CompoundPredicate;
import org.apache.doris.analysis.Expr;
import org.apache.doris.analysis.InlineViewRef;
Expand All @@ -32,6 +31,9 @@
import org.apache.doris.metric.MetricRepo;
import org.apache.doris.qe.RowBatch;
import org.apache.doris.thrift.TUniqueId;

import com.google.common.collect.Lists;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down