Skip to content

Commit

Permalink
[BugFix] fix .net can not read sr (#51946)
Browse files Browse the repository at this point in the history
Signed-off-by: before-Sunrise <[email protected]>
(cherry picked from commit dbd40cd)

# Conflicts:
#	fe/fe-core/src/main/java/com/starrocks/sql/analyzer/ExpressionAnalyzer.java
#	fe/fe-core/src/test/java/com/starrocks/qe/VariableMgrTest.java
  • Loading branch information
before-Sunrise authored and mergify[bot] committed Oct 16, 2024
1 parent 018d885 commit 9a4393b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,7 @@ public Void visitInformationFunction(InformationFunction node, Scope context) {
@Override
public Void visitVariableExpr(VariableExpr node, Scope context) {
try {
<<<<<<< HEAD
if (node.getSetType() != null && node.getSetType().equals(SetType.USER)) {
UserVariable userVariable = session.getUserVariables(node.getName());
// If referring to an uninitialized variable, its value is NULL and a string type.
Expand All @@ -1685,6 +1686,17 @@ public Void visitVariableExpr(VariableExpr node, Scope context) {
node.setType(Type.VARCHAR);
node.setValue(SqlModeHelper.decode((long) node.getValue()));
}
=======
GlobalStateMgr.getCurrentState().getVariableMgr().fillValue(session.getSessionVariable(), node);
if (!Strings.isNullOrEmpty(node.getName()) &&
node.getName().equalsIgnoreCase(SessionVariable.SQL_MODE)) {
node.setType(Type.VARCHAR);
node.setValue(SqlModeHelper.decode((long) node.getValue()));
} else if (!Strings.isNullOrEmpty(node.getName()) &&
node.getName().equalsIgnoreCase(SessionVariable.AUTO_COMMIT)) {
node.setType(Type.BIGINT);
node.setValue(((boolean) node.getValue()) ? (long) (1) : (long) 0);
>>>>>>> dbd40cd4aa ([BugFix] fix .net can not read sr (#51946))
}
} catch (DdlException e) {
throw new SemanticException(e.getMessage());
Expand Down
46 changes: 46 additions & 0 deletions fe/fe-core/src/test/java/com/starrocks/qe/VariableMgrTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@
import com.starrocks.analysis.IntLiteral;
import com.starrocks.analysis.StringLiteral;
import com.starrocks.analysis.VariableExpr;
import com.starrocks.catalog.PrimitiveType;
import com.starrocks.catalog.ScalarType;
import com.starrocks.common.AnalysisException;
import com.starrocks.common.DdlException;
import com.starrocks.common.UserException;
import com.starrocks.mysql.privilege.Auth;
import com.starrocks.mysql.privilege.PrivPredicate;
import com.starrocks.persist.EditLog;
import com.starrocks.server.GlobalStateMgr;
import com.starrocks.sql.analyzer.ExpressionAnalyzer;
import com.starrocks.sql.analyzer.SemanticException;
import com.starrocks.sql.analyzer.SetStmtAnalyzer;
import com.starrocks.sql.ast.SetStmt;
Expand Down Expand Up @@ -288,5 +291,48 @@ public void testDumpInvisible() {
List<List<String>> vars2 = VariableMgr.dump(SetType.SESSION, null, null);
Assert.assertTrue(vars.size() == vars2.size());
}
<<<<<<< HEAD
=======

@Test
public void testWarehouseVar() {
SystemVariable systemVariable =
new SystemVariable(SetType.GLOBAL, SessionVariable.WAREHOUSE_NAME, new StringLiteral("warehouse_1"));
VariableMgr variableMgr = new VariableMgr();
try {
variableMgr.setSystemVariable(null, systemVariable, false);
} catch (DdlException e) {
Assert.assertEquals("Variable 'warehouse' is a SESSION variable and can't be used with SET GLOBAL",
e.getMessage());
}
}

@Test
public void testImagePersist() throws Exception {
UtFrameUtils.PseudoImage.setUpImageVersion();
VariableMgr mgr = new VariableMgr();
GlobalVarPersistInfo info = new GlobalVarPersistInfo();
info.setPersistJsonString("{\"query_timeout\":100}");
mgr.replayGlobalVariableV2(info);

PseudoImage image = new PseudoImage();
mgr.save(image.getImageWriter());

VariableMgr mgr2 = new VariableMgr();
mgr2.load(image.getMetaBlockReader());

Assert.assertEquals(100, mgr2.getDefaultSessionVariable().getQueryTimeoutS());
}

@Test
public void testAutoCommit() throws Exception {
VariableExpr desc = new VariableExpr("autocommit");
ExpressionAnalyzer.analyzeExpressionIgnoreSlot(desc, UtFrameUtils.createDefaultCtx());

Assert.assertEquals("autocommit", desc.getName());
Assert.assertEquals(ScalarType.createType(PrimitiveType.BIGINT), desc.getType());
Assert.assertEquals((long) desc.getValue(), 1);
}
>>>>>>> dbd40cd4aa ([BugFix] fix .net can not read sr (#51946))
}

0 comments on commit 9a4393b

Please sign in to comment.