Skip to content

Commit

Permalink
support Chinese character (#939)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyuankang committed Mar 24, 2020
1 parent 8b8d4c3 commit 9fe3895
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -823,20 +823,25 @@ DATETIME
(('+' | '-') INT ':' INT)?)?
;
/** Allow unicode rule/token names */
ID : NameChar NameChar*;
ID : NAME_CHAR NAME_CHAR*;

FILE
: (('a'..'z'| 'A'..'Z')(':')?)* (('\\' | '/')+ PATH_FRAGMENT) +
;

fragment
NameChar
NAME_CHAR
: 'A'..'Z'
| 'a'..'z'
| '0'..'9'
| '_'
| CN_CHAR
;

fragment CN_CHAR
: '\u2E80'..'\u9FFF'
;

fragment DOUBLE_QUOTE_STRING_LITERAL
: '"' ('\\' . | ~'"' )*? '"'
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@
*/
package org.apache.iotdb.db.qp.constant;

import org.apache.iotdb.tsfile.read.common.Path;

import java.util.HashMap;
import java.util.Map;

import org.apache.iotdb.db.qp.strategy.SqlBaseLexer;
import org.apache.iotdb.tsfile.read.common.Path;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.iotdb.db.qp.plan;

import java.util.ArrayList;
import org.antlr.v4.runtime.misc.ParseCancellationException;
import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.exception.query.LogicalOptimizeException;
Expand All @@ -27,6 +28,7 @@
import org.apache.iotdb.db.qp.logical.RootOperator;
import org.apache.iotdb.db.qp.logical.crud.QueryOperator;
import org.apache.iotdb.db.qp.logical.sys.DeleteStorageGroupOperator;
import org.apache.iotdb.db.qp.logical.sys.SetStorageGroupOperator;
import org.apache.iotdb.db.qp.strategy.ParseDriver;
import org.apache.iotdb.db.qp.strategy.optimizer.ConcatPathOptimizer;
import org.apache.iotdb.tsfile.read.common.Path;
Expand Down Expand Up @@ -195,24 +197,43 @@ public void testDeleteStorageGroup() {
public void testDisableAlign() {
String sqlStr = "select * from root.vehicle disable align";
RootOperator operator = (RootOperator) parseDriver
.parse(sqlStr, IoTDBDescriptor.getInstance().getConfig().getZoneID());
.parse(sqlStr, IoTDBDescriptor.getInstance().getConfig().getZoneID());
Assert.assertEquals(QueryOperator.class, operator.getClass());
Assert.assertFalse(((QueryOperator)operator).isAlignByTime());
Assert.assertFalse(((QueryOperator) operator).isAlignByTime());
}

@Test
public void testNotDisableAlign() {
String sqlStr = "select * from root.vehicle";
RootOperator operator = (RootOperator) parseDriver
.parse(sqlStr, IoTDBDescriptor.getInstance().getConfig().getZoneID());
.parse(sqlStr, IoTDBDescriptor.getInstance().getConfig().getZoneID());
Assert.assertEquals(QueryOperator.class, operator.getClass());
Assert.assertTrue(((QueryOperator)operator).isAlignByTime());
Assert.assertTrue(((QueryOperator) operator).isAlignByTime());
}

@Test (expected = ParseCancellationException.class)
@Test(expected = ParseCancellationException.class)
public void testDisableAlignConflictAlignByDevice() {
String sqlStr = "select * from root.vehicle disable align align by device";
RootOperator operator = (RootOperator) parseDriver
.parse(sqlStr, IoTDBDescriptor.getInstance().getConfig().getZoneID());
.parse(sqlStr, IoTDBDescriptor.getInstance().getConfig().getZoneID());
}

@Test
public void testChineseCharacter() {
String sqlStr1 = "set storage group to root.一级";
RootOperator operator = (RootOperator) parseDriver
.parse(sqlStr1, IoTDBDescriptor.getInstance().getConfig().getZoneID());
Assert.assertEquals(SetStorageGroupOperator.class, operator.getClass());
Assert.assertEquals(new Path("root.一级"), ((SetStorageGroupOperator) operator).getPath());

String sqlStr2 = "select * from root.一级.设备1 limit 10 offset 20";
operator = (RootOperator) parseDriver
.parse(sqlStr2, IoTDBDescriptor.getInstance().getConfig().getZoneID());
Assert.assertEquals(QueryOperator.class, operator.getClass());
ArrayList<Path> paths = new ArrayList<>();
paths.add(new Path("*"));
Assert.assertEquals(paths, ((QueryOperator) operator).getSelectedPaths());
}


}

0 comments on commit 9fe3895

Please sign in to comment.