Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Questdb
提交
39d02caf
Q
Questdb
项目概览
jobily
/
Questdb
11 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Q
Questdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
39d02caf
编写于
11月 04, 2021
作者:
P
Plamen Hristov
提交者:
GitHub
11月 04, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(sql): Fixed cast as column name (#1502)
上级
c5d9eb84
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
82 addition
and
4 deletion
+82
-4
core/src/main/java/io/questdb/griffin/ExpressionParser.java
core/src/main/java/io/questdb/griffin/ExpressionParser.java
+12
-1
core/src/main/java/io/questdb/griffin/SqlKeywords.java
core/src/main/java/io/questdb/griffin/SqlKeywords.java
+2
-0
core/src/test/java/io/questdb/griffin/ExpressionParserTest.java
...rc/test/java/io/questdb/griffin/ExpressionParserTest.java
+23
-3
core/src/test/java/io/questdb/griffin/SqlParserTest.java
core/src/test/java/io/questdb/griffin/SqlParserTest.java
+13
-0
core/src/test/java/io/questdb/griffin/TimestampQueryTest.java
.../src/test/java/io/questdb/griffin/TimestampQueryTest.java
+32
-0
未找到文件。
core/src/main/java/io/questdb/griffin/ExpressionParser.java
浏览文件 @
39d02caf
...
...
@@ -333,7 +333,7 @@ class ExpressionParser {
CharSequence
geohashTok
=
GenericLexer
.
immutableOf
(
tok
);
tok
=
SqlUtil
.
fetchNext
(
lexer
);
if
(
tok
==
null
||
tok
.
charAt
(
0
)
!=
'('
)
{
lexer
.
backTo
(
position
+
7
,
geohashTok
);
lexer
.
backTo
(
position
+
SqlKeywords
.
GEOHASH_KEYWORD_LENGTH
,
geohashTok
);
tok
=
geohashTok
;
processDefaultBranch
=
true
;
break
;
...
...
@@ -512,6 +512,17 @@ class ExpressionParser {
case
'c'
:
case
'C'
:
if
(
SqlKeywords
.
isCastKeyword
(
tok
))
{
CharSequence
caseTok
=
GenericLexer
.
immutableOf
(
tok
);
tok
=
SqlUtil
.
fetchNext
(
lexer
);
if
(
tok
==
null
||
tok
.
charAt
(
0
)
!=
'('
)
{
lexer
.
backTo
(
position
+
SqlKeywords
.
CASE_KEYWORD_LENGTH
,
caseTok
);
tok
=
caseTok
;
processDefaultBranch
=
true
;
break
;
}
lexer
.
backTo
(
position
+
SqlKeywords
.
CASE_KEYWORD_LENGTH
,
caseTok
);
tok
=
caseTok
;
if
(
prevBranch
!=
BRANCH_DOT_DEREFERENCE
)
{
castBraceCountStack
.
push
(-
1
);
thisBranch
=
BRANCH_OPERATOR
;
...
...
core/src/main/java/io/questdb/griffin/SqlKeywords.java
浏览文件 @
39d02caf
...
...
@@ -26,6 +26,8 @@ package io.questdb.griffin;
public
class
SqlKeywords
{
public
static
final
String
CONCAT_FUNC_NAME
=
"concat"
;
public
static
final
int
CASE_KEYWORD_LENGTH
=
4
;
public
static
int
GEOHASH_KEYWORD_LENGTH
=
7
;
public
static
boolean
isAddKeyword
(
CharSequence
tok
)
{
if
(
tok
.
length
()
!=
3
)
{
...
...
core/src/test/java/io/questdb/griffin/ExpressionParserTest.java
浏览文件 @
39d02caf
...
...
@@ -100,7 +100,7 @@ public class ExpressionParserTest extends AbstractCairoTest {
Numbers
.
encodeLowHighShorts
((
short
)
0
,
(
short
)
(
5
*
(
tok
.
length
()
-
1
))),
ExpressionParser
.
extractGeoHashSuffix
(
0
,
tok
));
}
for
(
String
tok
:
new
String
[]{
"#/x"
,
"#/1x"
,
"#/x1"
,
"#/xx"
,
"#/-1"
,
})
{
for
(
String
tok
:
new
String
[]{
"#/x"
,
"#/1x"
,
"#/x1"
,
"#/xx"
,
"#/-1"
,})
{
Assert
.
assertThrows
(
"[0] invalid bits size for GEOHASH constant"
,
SqlException
.
class
,
()
->
ExpressionParser
.
extractGeoHashSuffix
(
0
,
tok
));
}
...
...
@@ -438,10 +438,19 @@ public class ExpressionParserTest extends AbstractCairoTest {
" end + 1)"
);
}
@Test
public
void
testCaseWithDanglingCast
()
{
assertFail
(
"case (cast 1 as int)"
,
11
,
"dangling expression"
);
}
@Test
public
void
testCaseWithCast
()
throws
SqlException
{
x
(
"1
castin
t1'th1'2'th2'0case5*1+"
,
"case (cast
1 as int
)"
+
x
(
"1
intcas
t1'th1'2'th2'0case5*1+"
,
"case (cast
(1 as int)
)"
+
" when 1"
+
" then 'th1'"
+
" when 2"
+
...
...
@@ -450,6 +459,16 @@ public class ExpressionParserTest extends AbstractCairoTest {
" end * 5 + 1"
);
}
@Test
public
void
testCastFunctionCallMultiSpace
()
throws
SqlException
{
x
(
"1102030f+shortcast"
,
"cast\t --- this is a comment\n\n(1+f(10,20,30) as short\n)"
);
}
@Test
public
void
testCastFunctionWithLambdaMultiSpaceNewlineAndComment
()
throws
SqlException
{
x
(
"(select-choose a, b, c from (x))flongcast"
,
"cast --- this is a comment\n\n(f(select a,b,c from x) as long\n)"
);
}
@Test
public
void
testCaseWithOuterBraces
()
throws
SqlException
{
x
(
"10w11+10='th1'w23*1>'th2'0case1+*"
,
...
...
@@ -1120,6 +1139,7 @@ public class ExpressionParserTest extends AbstractCairoTest {
x
(
"i0.1e+3<90100case"
,
"case when i < 0.1e+3 then 90 else 100 end"
);
}
private
void
assertFail
(
String
content
,
int
pos
,
String
contains
)
{
try
{
compiler
.
testParseExpression
(
content
,
rpnBuilder
);
...
...
core/src/test/java/io/questdb/griffin/SqlParserTest.java
浏览文件 @
39d02caf
...
...
@@ -814,6 +814,19 @@ public class SqlParserTest extends AbstractSqlParserTest {
"PARTITION BY YEAR"
);
}
@Test
public
void
testCreateTableCastMultiSpaceMultiNewlineAndComment
()
throws
SqlException
{
assertCreateTable
(
"create table x as (select-choose a, b, c from (select [a, b, c] from tab)), cast(a as DOUBLE:38), cast(c as SYMBOL:83 capacity 16 cache)"
,
"create table x as (tab), cast (a as double ), cast\n--- this is a comment\n\n(c as symbol capacity 16\n)"
,
modelOf
(
"tab"
)
.
col
(
"a"
,
ColumnType
.
INT
)
.
col
(
"b"
,
ColumnType
.
LONG
)
.
col
(
"c"
,
ColumnType
.
STRING
)
);
}
@Test
public
void
testCreateTableCastCapacityDef
()
throws
SqlException
{
assertCreateTable
(
...
...
core/src/test/java/io/questdb/griffin/TimestampQueryTest.java
浏览文件 @
39d02caf
...
...
@@ -44,6 +44,37 @@ import java.util.stream.Stream;
public
class
TimestampQueryTest
extends
AbstractGriffinTest
{
@Test
public
void
testCast2AsValidColumnNameTouchFunction
()
throws
Exception
{
assertMemoryLeak
(()
->
{
//create table
String
createStmt
=
"create table xyz(time timestamp, cast2 geohash(8c)) timestamp(time) partition by DAY;"
;
compiler
.
compile
(
createStmt
,
sqlExecutionContext
);
//insert
executeInsert
(
"INSERT INTO xyz VALUES(1609459199000000, #u33d8b12)"
);
String
expected
=
"touch\n{\"data_pages\": 2, \"index_key_pages\":0, \"index_values_pages\": 0}\n"
;
String
query
=
"select touch(select time, cast2 from xyz);"
;
assertSql
(
query
,
expected
);
});
}
@Test
public
void
testCastAsValidColumnNameSelectTest
()
throws
Exception
{
assertMemoryLeak
(()
->
{
//create table
String
createStmt
=
"create table xyz(time timestamp, cast geohash(8c)) timestamp(time) partition by DAY;"
;
compiler
.
compile
(
createStmt
,
sqlExecutionContext
);
//insert
executeInsert
(
"INSERT INTO xyz VALUES(1609459199000000, #u33d8b12)"
);
String
expected
=
"time\tcast\n"
+
"2020-12-31T23:59:59.000000Z\tu33d8b12\n"
;
String
query
=
"select time, cast from xyz;"
;
assertSql
(
query
,
expected
);
});
}
@Test
public
void
testEqualityTimestampFormatYearAndMonthNegativeTest
()
throws
Exception
{
assertMemoryLeak
(()
->
{
...
...
@@ -1269,6 +1300,7 @@ public class TimestampQueryTest extends AbstractGriffinTest {
false
);
}
private
void
assertTimestampTtFailedQuery
(
String
expectedError
,
String
query
)
{
assertTimestampTtFailedQuery0
(
expectedError
,
query
);
String
dtsQuery
=
query
.
replace
(
"nts"
,
"dts"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录