提交 d3de5777 编写于 作者: V Vlad Ilyushchenko

GRIFFIN: symbol type cast for create table statement supports caching option...

GRIFFIN: symbol type cast for create table statement supports caching option and validates symbol capacity value
上级 fb9c774c
......@@ -383,6 +383,12 @@ public final class TableUtils {
}
}
public static void validateSymbolCapacityCached(boolean cache, int symbolCapacity, int cacheKeywordPosition) throws SqlException {
if (cache && symbolCapacity > MAX_SYMBOL_CAPACITY_CACHED) {
throw SqlException.$(cacheKeywordPosition, "max cached symbol capacity is ").put(MAX_SYMBOL_CAPACITY_CACHED);
}
}
static {
DateFormatCompiler compiler = new DateFormatCompiler();
fmtDay = compiler.compile("yyyy-MM-dd");
......
......@@ -703,9 +703,7 @@ public class SqlCompiler implements Closeable {
cache = configuration.getDefaultSymbolCacheFlag();
}
if (cache && symbolCapacity > TableUtils.MAX_SYMBOL_CAPACITY_CACHED) {
throw SqlException.$(lexer.lastTokenPosition(), "max cached symbol capacity is ").put(TableUtils.MAX_SYMBOL_CAPACITY_CACHED);
}
TableUtils.validateSymbolCapacityCached(cache, symbolCapacity, lexer.lastTokenPosition());
indexed = Chars.equalsNc("index", tok);
if (indexed) {
......@@ -1028,17 +1026,31 @@ public class SqlCompiler implements Closeable {
}
if (columnType == ColumnType.SYMBOL) {
int symbolCapacity = model.getSymbolCapacity(i);
if (symbolCapacity == -1) {
symbolCapacity = configuration.getDefaultSymbolCapacity();
final ColumnCastModel ccm = model.getColumnCastModels().get(metadata.getColumnName(i));
int symbolCapacity;
if (ccm != null) {
symbolCapacity = ccm.getSymbolCapacity();
} else {
symbolCapacity = model.getSymbolCapacity(i);
if (symbolCapacity == -1) {
symbolCapacity = configuration.getDefaultSymbolCapacity();
}
}
boolean cached;
if (ccm != null) {
cached = ccm.isCached();
} else {
cached = model.getSymbolCacheFlag(i);
}
SymbolMapWriter.createSymbolMapFiles(
ff,
mem,
path.trimTo(rootLen),
model.getColumnName(i),
symbolCapacity,
model.getSymbolCacheFlag(i)
cached
);
symbolMapCount++;
}
......
......@@ -339,11 +339,35 @@ public final class SqlParser {
columnCastModel.setType(type, columnName.position, columnType.position);
if (type == ColumnType.SYMBOL) {
if (Chars.equals(optTok(lexer), "capacity")) {
columnCastModel.setSymbolCapacity(parseSymbolCapacity(lexer));
CharSequence tok = tok(lexer, "'capacity', 'nocache', 'cache', 'index' or ')'");
int symbolCapacity;
int capacityPosition;
if (Chars.equals(tok, "capacity")) {
capacityPosition = lexer.getPosition();
columnCastModel.setSymbolCapacity(symbolCapacity = parseSymbolCapacity(lexer));
tok = tok(lexer, "'nocache', 'cache', 'index' or ')'");
} else {
lexer.unparse();
columnCastModel.setSymbolCapacity(configuration.getDefaultSymbolCapacity());
symbolCapacity = -1;
capacityPosition = -1;
}
final boolean cached;
if (Chars.equals(tok, "nocache")) {
cached = false;
} else if (Chars.equals(tok, "cache")) {
cached = true;
} else {
cached = configuration.getDefaultSymbolCacheFlag();
lexer.unparse();
}
columnCastModel.setCached(cached);
if (cached && symbolCapacity != -1) {
assert capacityPosition != -1;
TableUtils.validateSymbolCapacityCached(true, symbolCapacity, capacityPosition);
}
}
......@@ -371,18 +395,28 @@ public final class SqlParser {
case ColumnType.SYMBOL:
tok = tok(lexer, "'capacity', 'nocache', 'cache', 'index' or ')'");
int symbolCapacity;
if (Chars.equals(tok, "capacity")) {
model.symbolCapacity(parseSymbolCapacity(lexer));
// when capacity is not set explicitly it will default via configuration
model.symbolCapacity(symbolCapacity = parseSymbolCapacity(lexer));
tok = tok(lexer, "'nocache', 'cache', 'index' or ')'");
} else {
symbolCapacity = -1;
}
final boolean cached;
if (Chars.equals(tok, "nocache")) {
model.cached(false);
cached = false;
} else if (Chars.equals(tok, "cache")) {
model.cached(true);
cached = true;
} else {
cached = configuration.getDefaultSymbolCacheFlag();
lexer.unparse();
}
model.cached(cached);
if (cached && symbolCapacity != -1) {
TableUtils.validateSymbolCapacityCached(true, symbolCapacity, lexer.lastTokenPosition());
}
tok = parseCreateTableInlineIndexDef(lexer, model);
break;
default:
......
......@@ -34,6 +34,7 @@ public class ColumnCastModel implements Mutable {
private int columnTypePos;
private int columnNamePos;
private int symbolCapacity;
private boolean cached;
private ColumnCastModel() {
}
......@@ -71,6 +72,14 @@ public class ColumnCastModel implements Mutable {
this.symbolCapacity = symbolCapacity;
}
public boolean isCached() {
return cached;
}
public void setCached(boolean cached) {
this.cached = cached;
}
public void setType(int columnType, int columnNamePos, int columnTypePos) {
this.columnType = columnType;
this.columnNamePos = columnNamePos;
......
......@@ -647,7 +647,7 @@ public class SqlParserTest extends AbstractGriffinTest {
}
@Test
public void testCreateTableCastRoundedCapacityDef() throws SqlException {
public void testCreateTableCastRoundedSymbolCapacityDef() throws SqlException {
// 20 is rounded to next power of 2, which is 32
assertCreateTable(
"create table x as (select-choose a, b, c from (tab)), cast(a as DOUBLE:35), cast(c as SYMBOL:54 capacity 32)",
......@@ -1084,7 +1084,7 @@ public class SqlParserTest extends AbstractGriffinTest {
}
@Test
public void testCreateTableSymbolCapacityRounding() throws SqlException {
public void testCreateTableRoundedSymbolCapacity() throws SqlException {
assertCreateTable(
"create table x (" +
"a INT," +
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册