add |,||,&,&& for or/and in sql (#105)

This commit is contained in:
XuYi 2017-09-22 19:36:31 +08:00 committed by jixuan1989
parent 922b00b9ba
commit 6172d86c39
3 changed files with 18 additions and 27 deletions

View File

@ -20,8 +20,8 @@ KW_ENCODING: 'ENCODING';
KW_STORAGE: 'STORAGE';
KW_AND : 'AND';
KW_OR : 'OR';
KW_AND : 'AND' | '&' | '&&';
KW_OR : 'OR' | '|' | '||';
KW_NOT : 'NOT' | '!';

View File

@ -3,8 +3,6 @@ package cn.edu.tsinghua.iotdb.service;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanRegistrationException;
@ -28,23 +26,14 @@ import cn.edu.tsinghua.iotdb.exception.FileNodeManagerException;
import cn.edu.tsinghua.iotdb.exception.StartupException;
import cn.edu.tsinghua.iotdb.qp.QueryProcessor;
import cn.edu.tsinghua.iotdb.qp.constant.SQLConstant;
import cn.edu.tsinghua.iotdb.qp.executor.OverflowQPExecutor;
import cn.edu.tsinghua.iotdb.qp.physical.crud.DeletePlan;
import cn.edu.tsinghua.iotdb.qp.physical.crud.InsertPlan;
import cn.edu.tsinghua.iotdb.qp.physical.crud.UpdatePlan;
import cn.edu.tsinghua.iotdb.sys.writelog.WriteLogManager;
import cn.edu.tsinghua.tsfile.file.metadata.enums.TSDataType;
import cn.edu.tsinghua.tsfile.timeseries.read.qp.Path;
import cn.edu.tsinghua.tsfile.timeseries.write.record.DataPoint;
import cn.edu.tsinghua.tsfile.timeseries.write.record.TSRecord;
import org.apache.thrift.transport.TTransportException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cn.edu.tsinghua.iotdb.qp.physical.PhysicalPlan;
import cn.edu.tsinghua.iotdb.sys.writelog.WriteLogManager;
import cn.edu.tsinghua.tsfile.common.exception.ProcessorException;
public class Daemon {
@ -157,7 +146,7 @@ public class Daemon {
*/
private void systemDataRecovery() throws IOException, FileNodeManagerException, PathErrorException {
LOGGER.info("{}: start checking write log...",TsFileDBConstant.GLOBAL_DB_NAME);
QueryProcessor processor = new QueryProcessor(new OverflowQPExecutor());
// QueryProcessor processor = new QueryProcessor(new OverflowQPExecutor());
WriteLogManager writeLogManager = WriteLogManager.getInstance();
writeLogManager.recovery();
long cnt = 0L;

View File

@ -269,10 +269,12 @@ public class SQLParserTest {
@Test
public void delete5() throws ParseException {
// template for test case
ArrayList<String> ans = new ArrayList<>(Arrays.asList("TOK_DELETE", "TOK_PATH", "d1", "*", "TOK_PATH", "*", "s2", "TOK_WHERE", "<",
"TOK_PATH", "time", "123456"));
ArrayList<String> ans = new ArrayList<>(Arrays.asList("TOK_DELETE",
"TOK_PATH", "d1", "*",
"TOK_PATH", "*", "s2", "TOK_WHERE",
"!", "<", "TOK_PATH", "time", "123456"));
ArrayList<String> rec = new ArrayList<>();
ASTNode astTree = ParseGenerator.generateAST("delete from d1.*,*.s2 where time < 123456");
ASTNode astTree = ParseGenerator.generateAST("delete from d1.*,*.s2 where !(time < 123456)");
astTree = ParseUtils.findRootNonNullToken(astTree);
recursivePrintSon(astTree, rec);
@ -359,10 +361,10 @@ public class SQLParserTest {
"TOK_PATH", "device_2", "sensor_2",
"TOK_FROM", "TOK_PATH", "root", "vehicle",
"TOK_WHERE", "and",
"<", "TOK_PATH", "root", "laptop", "device_1", "sensor_1", "2000",
"not", "<", "TOK_PATH", "root", "laptop", "device_1", "sensor_1", "2000",
">", "TOK_PATH", "root", "laptop", "device_2", "sensor_2", "1000"));
ArrayList<String> rec = new ArrayList<>();
ASTNode astTree = ParseGenerator.generateAST("SELECT device_1.sensor_1,device_2.sensor_2 FROM root.vehicle WHERE root.laptop.device_1.sensor_1 < 2000 and root.laptop.device_2.sensor_2 > 1000");
ASTNode astTree = ParseGenerator.generateAST("SELECT device_1.sensor_1,device_2.sensor_2 FROM root.vehicle WHERE not(root.laptop.device_1.sensor_1 < 2000) and root.laptop.device_2.sensor_2 > 1000");
astTree = ParseUtils.findRootNonNullToken(astTree);
recursivePrintSon(astTree, rec);
@ -380,11 +382,11 @@ public class SQLParserTest {
"TOK_PATH", "device_1", "sensor_1",
"TOK_PATH", "device_2", "sensor_2",
"TOK_FROM", "TOK_PATH", "root", "vehicle",
"TOK_WHERE", "or",
"TOK_WHERE", "&&",
"<", "TOK_PATH", "root", "laptop", "device_1", "sensor_1", "-2.2E10",
">", "TOK_PATH", "time", "TOK_DATETIME" ,"now"));
ArrayList<String> rec = new ArrayList<>();
ASTNode astTree = ParseGenerator.generateAST("SELECT device_1.sensor_1,device_2.sensor_2 FROM root.vehicle WHERE root.laptop.device_1.sensor_1 < -2.2E10 or time > now()");
ASTNode astTree = ParseGenerator.generateAST("SELECT device_1.sensor_1,device_2.sensor_2 FROM root.vehicle WHERE root.laptop.device_1.sensor_1 < -2.2E10 && time > now()");
astTree = ParseUtils.findRootNonNullToken(astTree);
recursivePrintSon(astTree, rec);
@ -402,11 +404,11 @@ public class SQLParserTest {
"TOK_PATH", "device_1", "sensor_1",
"TOK_PATH", "device_2", "sensor_2",
"TOK_FROM", "TOK_PATH", "root", "vehicle",
"TOK_WHERE", "or",
"TOK_WHERE", "&",
"<", "TOK_PATH", "time", "1234567",
">", "TOK_PATH", "time", "TOK_DATETIME" ,"2017-6-2T12:00:12+07:00"));
ArrayList<String> rec = new ArrayList<>();
ASTNode astTree = ParseGenerator.generateAST("SELECT device_1.sensor_1,device_2.sensor_2 FROM root.vehicle WHERE time < 1234567 or time > 2017-6-2T12:00:12+07:00");
ASTNode astTree = ParseGenerator.generateAST("SELECT device_1.sensor_1,device_2.sensor_2 FROM root.vehicle WHERE time < 1234567 & time > 2017-6-2T12:00:12+07:00");
astTree = ParseUtils.findRootNonNullToken(astTree);
recursivePrintSon(astTree, rec);
@ -423,11 +425,11 @@ public class SQLParserTest {
ArrayList<String> ans = new ArrayList<>(Arrays.asList("TOK_QUERY", "TOK_SELECT",
"TOK_PATH", "*",
"TOK_FROM", "TOK_PATH", "root", "vehicle",
"TOK_WHERE", "or",
"TOK_WHERE", "||",
"<", "TOK_PATH", "time", "1234567",
">", "TOK_PATH", "time", "TOK_DATETIME" ,"2017-6-2T12:00:12+07:00"));
ArrayList<String> rec = new ArrayList<>();
ASTNode astTree = ParseGenerator.generateAST("SELECT * FROM root.vehicle WHERE time < 1234567 or time > 2017-6-2T12:00:12+07:00");
ASTNode astTree = ParseGenerator.generateAST("SELECT * FROM root.vehicle WHERE time < 1234567 || time > 2017-6-2T12:00:12+07:00");
astTree = ParseUtils.findRootNonNullToken(astTree);
recursivePrintSon(astTree, rec);
@ -491,11 +493,11 @@ public class SQLParserTest {
"TOK_PATH", "s1",
"TOK_PATH", "TOK_CLUSTER", "TOK_PATH", "s2", "sum",
"TOK_FROM", "TOK_PATH", "root", "vehicle", "d1",
"TOK_WHERE", "or",
"TOK_WHERE", "|",
"<", "TOK_PATH", "root", "vehicle", "d1", "s1", "2000",
">=", "TOK_PATH", "time", "1234567"));
ArrayList<String> rec = new ArrayList<>();
ASTNode astTree = ParseGenerator.generateAST("select s1,sum(s2) FROM root.vehicle.d1 WHERE root.vehicle.d1.s1 < 2000 or time >= 1234567");
ASTNode astTree = ParseGenerator.generateAST("select s1,sum(s2) FROM root.vehicle.d1 WHERE root.vehicle.d1.s1 < 2000 | time >= 1234567");
astTree = ParseUtils.findRootNonNullToken(astTree);
recursivePrintSon(astTree, rec);