Support sql mode (#2083)
At present, we do not support SQL MODE which is similar to MySQL. In MySQL, SQL MODE is stored in global session and session with a 64 bit address,and every bit 0 or 1 on this address represents a mode state. Besides, MySQL supports combine mode which is composed of several modes. We should support SQL MODE to deal with sql dialect problems. We can heuristically use the MySQL way to store SQL MODE in session and parse it into string when we need to return it back to client. This commit suggests a solution to support SQL MODE. But it's just a sample, and the mode types in SqlModeHelper.java are not really meaningful from now on.
This commit is contained in:
@ -23,6 +23,7 @@ import org.apache.doris.mysql.privilege.MockedAuth;
|
||||
import org.apache.doris.mysql.privilege.PaloAuth;
|
||||
import org.apache.doris.qe.ConnectContext;
|
||||
|
||||
import org.apache.doris.qe.SqlModeHelper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -73,4 +74,18 @@ public class SetVarTest {
|
||||
var.analyze(analyzer);
|
||||
Assert.fail("No exception throws.");
|
||||
}
|
||||
|
||||
@Test(expected = AnalysisException.class)
|
||||
public void testInvalidSqlModeValue() throws UserException, AnalysisException {
|
||||
SetVar var = new SetVar(SetType.SESSION, "sql_mode", new IntLiteral(SqlModeHelper.MODE_LAST));
|
||||
var.analyze(analyzer);
|
||||
Assert.fail("No exception throws");
|
||||
}
|
||||
|
||||
@Test(expected = AnalysisException.class)
|
||||
public void testInvalidSqlMode() throws UserException, AnalysisException {
|
||||
SetVar var = new SetVar(SetType.SESSION, "sql_mode", new StringLiteral("WRONG_MODE"));
|
||||
var.analyze(analyzer);
|
||||
Assert.fail("No exception throws");
|
||||
}
|
||||
}
|
||||
@ -49,4 +49,5 @@ public class SysVariableDescTest {
|
||||
desc.analyze(AccessTestUtil.fetchAdminAnalyzer(false));
|
||||
Assert.fail("No exception throws.");
|
||||
}
|
||||
|
||||
}
|
||||
61
fe/src/test/java/org/apache/doris/qe/SqlModeHelperTest.java
Normal file
61
fe/src/test/java/org/apache/doris/qe/SqlModeHelperTest.java
Normal file
@ -0,0 +1,61 @@
|
||||
// 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.qe;
|
||||
|
||||
import org.apache.doris.common.AnalysisException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SqlModeHelperTest {
|
||||
|
||||
@Test
|
||||
public void testNormal() throws AnalysisException {
|
||||
String sqlMode = "PIPES_AS_CONCAT";
|
||||
Assert.assertEquals(new Long(2L), SqlModeHelper.encode(sqlMode));
|
||||
|
||||
sqlMode = "";
|
||||
Assert.assertEquals(new Long(0L), SqlModeHelper.encode(sqlMode));
|
||||
|
||||
long sqlModeValue = 2L;
|
||||
Assert.assertEquals("PIPES_AS_CONCAT", SqlModeHelper.decode(sqlModeValue));
|
||||
|
||||
sqlModeValue = 0L;
|
||||
Assert.assertEquals("", SqlModeHelper.decode(sqlModeValue));
|
||||
}
|
||||
|
||||
@Test(expected = AnalysisException.class)
|
||||
public void testInvalidSqlMode() throws AnalysisException {
|
||||
String sqlMode = "PIPES_AS_CONCAT, WRONG_MODE";
|
||||
SqlModeHelper.encode(sqlMode);
|
||||
Assert.fail("No exception throws");
|
||||
}
|
||||
|
||||
@Test(expected = AnalysisException.class)
|
||||
public void testMultiSqlMode() throws AnalysisException {
|
||||
String sqlMode = "ANSI, TRADITIONAL";
|
||||
SqlModeHelper.encode(sqlMode);
|
||||
Assert.fail("No exception throws");
|
||||
}
|
||||
|
||||
@Test(expected = AnalysisException.class)
|
||||
public void testInvalidDecode() throws AnalysisException {
|
||||
long sqlMode = SqlModeHelper.MODE_LAST;
|
||||
SqlModeHelper.decode(sqlMode);
|
||||
Assert.fail("No exception throws");
|
||||
}
|
||||
}
|
||||
@ -71,6 +71,7 @@ public class VariableMgrTest {
|
||||
Assert.assertEquals(2147483648L, var.getMaxExecMemByte());
|
||||
Assert.assertEquals(300, var.getQueryTimeoutS());
|
||||
Assert.assertEquals(false, var.isReportSucc());
|
||||
Assert.assertEquals(0L, var.getSqlMode());
|
||||
|
||||
List<List<String>> rows = VariableMgr.dump(SetType.SESSION, var, null);
|
||||
Assert.assertTrue(rows.size() > 5);
|
||||
@ -117,6 +118,12 @@ public class VariableMgrTest {
|
||||
// Get from name
|
||||
SysVariableDesc desc = new SysVariableDesc("exec_mem_limit");
|
||||
Assert.assertEquals(var.getMaxExecMemByte() + "", VariableMgr.getValue(var, desc));
|
||||
|
||||
SetVar setVar4 = new SetVar(SetType.SESSION, "sql_mode", new StringLiteral(
|
||||
SqlModeHelper.encode("PIPES_AS_CONCAT").toString()));
|
||||
VariableMgr.setVar(var, setVar4);
|
||||
Assert.assertEquals(2L, var.getSqlMode());
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = DdlException.class)
|
||||
@ -161,7 +168,6 @@ public class VariableMgrTest {
|
||||
Assert.fail("No exception throws.");
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = DdlException.class)
|
||||
public void testReadOnly() throws AnalysisException, DdlException {
|
||||
SysVariableDesc desc = new SysVariableDesc("version_comment");
|
||||
|
||||
Reference in New Issue
Block a user