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
12 changes: 12 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/qe/VariableMgr.java
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,18 @@ public static String getValue(SessionVariable var, VariableExpr desc) throws Ana
}

private static Literal getLiteral(Object obj, Field field) {
VarAttr attr = field.getAnnotation(VarAttr.class);
if (!Strings.isNullOrEmpty(attr.convertBoolToLongMethod())) {
try {
Preconditions.checkArgument(obj instanceof SessionVariable);
long val = (Long) SessionVariable.class.getDeclaredMethod(attr.convertBoolToLongMethod(), Boolean.class)
.invoke(obj, field.getBoolean(obj));
return Literal.of(Long.valueOf(val));
} catch (Exception e) {
// should not happen
LOG.warn("failed to convert bool to long for var: {}", field.getName(), e);
}
}
try {
switch (field.getType().getSimpleName()) {
case "boolean":
Expand Down
19 changes: 19 additions & 0 deletions fe/fe-core/src/test/java/org/apache/doris/qe/VariableMgrTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@
import org.apache.doris.analysis.VariableExpr;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.Config;
import org.apache.doris.common.DdlException;
import org.apache.doris.common.UserException;
import org.apache.doris.common.jmockit.Deencapsulation;
import org.apache.doris.nereids.trees.expressions.literal.Literal;
import org.apache.doris.nereids.types.BigIntType;
import org.apache.doris.utframe.UtFrameUtils;

import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -273,4 +276,20 @@ public void testAutoCommitConvert() throws Exception {
Assert.assertTrue(desc.getLiteralExpr() instanceof BoolLiteral);
Assert.assertEquals(Type.BOOLEAN, desc.getType());
}

// @@auto_commit's type should be BIGINT
@Test
public void testAutoCommitType() throws AnalysisException {
// Old planner
SessionVariable sv = new SessionVariable();
VariableExpr desc = new VariableExpr(SessionVariable.AUTO_COMMIT);
VariableMgr.fillValue(sv, desc);
Assert.assertEquals(Type.BIGINT, desc.getType());
// Nereids
sv = new SessionVariable();
String name = SessionVariable.AUTO_COMMIT;
SetType setType = SetType.SESSION;
Literal l = VariableMgr.getLiteral(sv, name, setType);
Assert.assertEquals(BigIntType.INSTANCE, l.getDataType());
}
}