提交 5c739ab0 编写于 作者: V Vlad Ilyushchenko

GRIFFIN: renamed 'to_char' for date and timestamp to 'to_str' to make them easier to find

上级 793cc26e
......@@ -21,7 +21,7 @@
*
******************************************************************************/
package io.questdb.griffin.engine.functions.str;
package io.questdb.griffin.engine.functions.date;
import io.questdb.cairo.CairoConfiguration;
import io.questdb.cairo.sql.Function;
......@@ -42,14 +42,14 @@ import io.questdb.std.time.DateLocale;
import io.questdb.std.time.DateLocaleFactory;
import org.jetbrains.annotations.Nullable;
public class ToCharDateFunctionFactory implements FunctionFactory {
public class ToStrDateFunctionFactory implements FunctionFactory {
private static final ThreadLocal<DateFormatCompiler> tlCompiler = ThreadLocal.withInitial(DateFormatCompiler::new);
private static final ThreadLocal<StringSink> tlSink = ThreadLocal.withInitial(StringSink::new);
@Override
public String getSignature() {
return "to_char(Ms)";
return "to_str(Ms)";
}
@Override
......
......@@ -21,7 +21,7 @@
*
******************************************************************************/
package io.questdb.griffin.engine.functions.str;
package io.questdb.griffin.engine.functions.date;
import io.questdb.cairo.CairoConfiguration;
import io.questdb.cairo.sql.Function;
......@@ -42,14 +42,14 @@ import io.questdb.std.str.CharSink;
import io.questdb.std.str.StringSink;
import org.jetbrains.annotations.Nullable;
public class ToCharTimestampFunctionFactory implements FunctionFactory {
public class ToStrTimestampFunctionFactory implements FunctionFactory {
private static final ThreadLocal<DateFormatCompiler> tlCompiler = ThreadLocal.withInitial(DateFormatCompiler::new);
private static final ThreadLocal<StringSink> tlSink = ThreadLocal.withInitial(StringSink::new);
@Override
public String getSignature() {
return "to_char(Ns)";
return "to_str(Ns)";
}
@Override
......
......@@ -21,29 +21,6 @@
#
################################################################################
################################################################################
# ___ _ ____ ____
# / _ \ _ _ ___ ___| |_| _ \| __ )
# | | | | | | |/ _ \/ __| __| | | | _ \
# | |_| | |_| | __/\__ \ |_| |_| | |_) |
# \__\_\\__,_|\___||___/\__|____/|____/
#
# Copyright (C) 2014-2019 Appsicle
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3,
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
# logical operations
io.questdb.griffin.engine.functions.bool.OrFunctionFactory
io.questdb.griffin.engine.functions.bool.AndFunctionFactory
......@@ -109,8 +86,8 @@ io.questdb.griffin.engine.functions.regex.MatchCharFunctionFactory
io.questdb.griffin.engine.functions.regex.NotMatchStrFunctionFactory
# 'to_char'
io.questdb.griffin.engine.functions.str.ToCharDateFunctionFactory
io.questdb.griffin.engine.functions.str.ToCharTimestampFunctionFactory
io.questdb.griffin.engine.functions.date.ToStrDateFunctionFactory
io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory
io.questdb.griffin.engine.functions.str.ToCharBinFunctionFactory
# 'to_symbol'
......@@ -150,11 +127,11 @@ io.questdb.griffin.engine.functions.rnd.RndLong256FunctionFactory
io.questdb.griffin.engine.functions.date.SysdateFunctionFactory
io.questdb.griffin.engine.functions.date.ToTimestampVCFunctionFactory
io.questdb.griffin.engine.functions.str.ToCharTimestampFunctionFactory
io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory
io.questdb.griffin.engine.functions.cast.SecondsToTimestampFunctionFactory
io.questdb.griffin.engine.functions.date.ToDateFunctionFactory
io.questdb.griffin.engine.functions.str.ToCharDateFunctionFactory
io.questdb.griffin.engine.functions.date.ToStrDateFunctionFactory
# cast functions
io.questdb.griffin.engine.functions.cast.ToDateLongFunctionFactory
......
......@@ -33,8 +33,12 @@ import io.questdb.griffin.engine.functions.bool.NotFunctionFactory;
import io.questdb.griffin.engine.functions.bool.OrFunctionFactory;
import io.questdb.griffin.engine.functions.constants.*;
import io.questdb.griffin.engine.functions.date.SysdateFunctionFactory;
import io.questdb.griffin.engine.functions.date.ToStrDateFunctionFactory;
import io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory;
import io.questdb.griffin.engine.functions.math.*;
import io.questdb.griffin.engine.functions.str.*;
import io.questdb.griffin.engine.functions.str.LengthStrFunctionFactory;
import io.questdb.griffin.engine.functions.str.LengthSymbolFunctionFactory;
import io.questdb.griffin.engine.functions.str.ToCharBinFunctionFactory;
import io.questdb.std.BinarySequence;
import io.questdb.std.NumericException;
import io.questdb.std.ObjList;
......@@ -355,8 +359,8 @@ public class FunctionParserTest extends BaseFunctionFactoryTest {
@Test
public void testFunctionOverload() throws SqlException {
functions.add(new ToCharDateFunctionFactory());
functions.add(new ToCharTimestampFunctionFactory());
functions.add(new ToStrDateFunctionFactory());
functions.add(new ToStrTimestampFunctionFactory());
functions.add(new ToCharBinFunctionFactory());
final GenericRecordMetadata metadata = new GenericRecordMetadata();
......@@ -367,11 +371,11 @@ public class FunctionParserTest extends BaseFunctionFactoryTest {
FunctionParser functionParser = createFunctionParser();
Record record = new TestRecord();
Function function = parseFunction("to_char(a, 'EE, dd-MMM-yyyy hh:mm:ss')", metadata, functionParser);
Function function = parseFunction("to_str(a, 'EE, dd-MMM-yyyy hh:mm:ss')", metadata, functionParser);
Assert.assertEquals(ColumnType.STRING, function.getType());
TestUtils.assertEquals("Thursday, 03-Apr-150577 03:54:03", function.getStr(record));
Function function2 = parseFunction("to_char(b, 'EE, dd-MMM-yyyy hh:mm:ss')", metadata, functionParser);
Function function2 = parseFunction("to_str(b, 'EE, dd-MMM-yyyy hh:mm:ss')", metadata, functionParser);
Assert.assertEquals(ColumnType.STRING, function2.getType());
TestUtils.assertEquals("Tuesday, 21-Nov-2119 08:50:58", function2.getStr(record));
......@@ -928,7 +932,7 @@ public class FunctionParserTest extends BaseFunctionFactoryTest {
@Test
public void testNoArgFunction() throws SqlException, JsonException {
functions.add(new SysdateFunctionFactory());
functions.add(new ToCharDateFunctionFactory());
functions.add(new ToStrDateFunctionFactory());
FunctionParser functionParser = new FunctionParser(
new DefaultCairoConfiguration(root) {
@Override
......@@ -945,7 +949,7 @@ public class FunctionParserTest extends BaseFunctionFactoryTest {
},
functions);
Function function = parseFunction("to_char(sysdate(), 'EE, dd-MMM-yyyy HH:mm:ss')",
Function function = parseFunction("to_str(sysdate(), 'EE, dd-MMM-yyyy HH:mm:ss')",
new GenericRecordMetadata(),
functionParser
);
......
......@@ -34,9 +34,14 @@ import io.questdb.griffin.FunctionParser;
import io.questdb.griffin.SqlException;
import io.questdb.griffin.engine.TestBinarySequence;
import io.questdb.griffin.engine.functions.bool.NotFunctionFactory;
import io.questdb.griffin.engine.functions.date.ToStrDateFunctionFactory;
import io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory;
import io.questdb.griffin.engine.functions.eq.EqLong256FunctionFactory;
import io.questdb.griffin.engine.functions.math.*;
import io.questdb.griffin.engine.functions.str.*;
import io.questdb.griffin.engine.functions.str.LengthBinFunctionFactory;
import io.questdb.griffin.engine.functions.str.LengthStrFunctionFactory;
import io.questdb.griffin.engine.functions.str.SubStrFunctionFactory;
import io.questdb.griffin.engine.functions.str.ToCharBinFunctionFactory;
import io.questdb.std.*;
import io.questdb.std.time.DateFormatUtils;
import io.questdb.test.tools.TestUtils;
......@@ -59,9 +64,9 @@ public class BindVariablesTest extends BaseFunctionFactoryTest {
bindVariableService.setDate("xyz", 0);
Function func = expr("to_char(:xyz, 'yyyy-MM')")
.withFunction(new ToCharDateFunctionFactory())
.withFunction(new ToCharTimestampFunctionFactory())
Function func = expr("to_str(:xyz, 'yyyy-MM')")
.withFunction(new ToStrDateFunctionFactory())
.withFunction(new ToStrTimestampFunctionFactory())
.$();
func.init(null, sqlExecutionContext);
......@@ -77,7 +82,7 @@ public class BindVariablesTest extends BaseFunctionFactoryTest {
Function func = expr("to_char(:x)")
.withFunction(new ToCharBinFunctionFactory())
.withFunction(new ToCharTimestampFunctionFactory())
.withFunction(new ToStrTimestampFunctionFactory())
.$();
func.init(null, sqlExecutionContext);
......@@ -133,7 +138,7 @@ public class BindVariablesTest extends BaseFunctionFactoryTest {
Function func = expr("to_char($1)")
.withFunction(new ToCharBinFunctionFactory())
.withFunction(new ToCharTimestampFunctionFactory())
.withFunction(new ToStrTimestampFunctionFactory())
.$();
func.init(null, sqlExecutionContext);
......@@ -242,8 +247,8 @@ public class BindVariablesTest extends BaseFunctionFactoryTest {
@Test
public void testDate() throws SqlException, NumericException {
bindVariableService.setDate("xyz", DateFormatUtils.parseDateTime("2015-04-10T10:00:00.000Z"));
Function func = expr("to_char(:xyz, 'yyyy-MM')")
.withFunction(new ToCharDateFunctionFactory())
Function func = expr("to_str(:xyz, 'yyyy-MM')")
.withFunction(new ToStrDateFunctionFactory())
.$();
func.init(null, sqlExecutionContext);
......@@ -270,8 +275,8 @@ public class BindVariablesTest extends BaseFunctionFactoryTest {
public void testDateIndexed() throws SqlException, NumericException {
bindVariableService.setDate(1, 0);
bindVariableService.setDate(0, DateFormatUtils.parseDateTime("2015-04-10T10:00:00.000Z"));
Function func = expr("to_char($1, 'yyyy-MM')")
.withFunction(new ToCharDateFunctionFactory())
Function func = expr("to_str($1, 'yyyy-MM')")
.withFunction(new ToStrDateFunctionFactory())
.$();
func.init(null, sqlExecutionContext);
......@@ -657,8 +662,8 @@ public class BindVariablesTest extends BaseFunctionFactoryTest {
public void testTimestamp() throws SqlException, NumericException {
bindVariableService.setTimestamp("xyz", io.questdb.std.microtime.DateFormatUtils.parseDateTime("2015-04-10T10:00:00.000Z"));
Function func = expr("to_char(:xyz, 'yyyy-MM')")
.withFunction(new ToCharTimestampFunctionFactory())
Function func = expr("to_str(:xyz, 'yyyy-MM')")
.withFunction(new ToStrTimestampFunctionFactory())
.$();
func.init(null, sqlExecutionContext);
......@@ -673,8 +678,8 @@ public class BindVariablesTest extends BaseFunctionFactoryTest {
bindVariableService.setTimestamp(1, 25);
bindVariableService.setTimestamp(0, io.questdb.std.microtime.DateFormatUtils.parseDateTime("2015-04-10T10:00:00.000Z"));
Function func = expr("to_char($1, 'yyyy-MM')")
.withFunction(new ToCharTimestampFunctionFactory())
Function func = expr("to_str($1, 'yyyy-MM')")
.withFunction(new ToStrTimestampFunctionFactory())
.$();
func.init(null, sqlExecutionContext);
......@@ -688,8 +693,8 @@ public class BindVariablesTest extends BaseFunctionFactoryTest {
public void testUndefined() {
try {
expr("to_char(:xyz, 'yyyy-MM')")
.withFunction(new ToCharDateFunctionFactory())
.withFunction(new ToCharTimestampFunctionFactory())
.withFunction(new ToStrDateFunctionFactory())
.withFunction(new ToStrTimestampFunctionFactory())
.$();
} catch (SqlException e) {
Assert.assertEquals(8, e.getPosition());
......@@ -701,8 +706,8 @@ public class BindVariablesTest extends BaseFunctionFactoryTest {
public void testUndefinedIndexed() {
try {
expr("to_char($1, 'yyyy-MM')")
.withFunction(new ToCharDateFunctionFactory())
.withFunction(new ToCharTimestampFunctionFactory())
.withFunction(new ToStrDateFunctionFactory())
.withFunction(new ToStrTimestampFunctionFactory())
.$();
} catch (SqlException e) {
Assert.assertEquals(8, e.getPosition());
......
......@@ -26,6 +26,7 @@ package io.questdb.griffin.engine.functions.str;
import io.questdb.griffin.FunctionFactory;
import io.questdb.griffin.SqlException;
import io.questdb.griffin.engine.AbstractFunctionFactoryTest;
import io.questdb.griffin.engine.functions.date.ToStrDateFunctionFactory;
import io.questdb.std.Numbers;
import io.questdb.std.NumericException;
import io.questdb.std.time.DateFormatUtils;
......@@ -39,7 +40,7 @@ public class ToCharDateVCFunctionFactoryTest extends AbstractFunctionFactoryTest
@Test
public void testNullFormat() {
assertFailure(11, "format must not be null", 0L, null);
assertFailure(10, "format must not be null", 0L, null);
}
@Test
......@@ -50,6 +51,6 @@ public class ToCharDateVCFunctionFactoryTest extends AbstractFunctionFactoryTest
@Override
protected FunctionFactory getFunctionFactory() {
return new ToCharDateFunctionFactory();
return new ToStrDateFunctionFactory();
}
}
\ No newline at end of file
......@@ -26,6 +26,7 @@ package io.questdb.griffin.engine.functions.str;
import io.questdb.griffin.FunctionFactory;
import io.questdb.griffin.SqlException;
import io.questdb.griffin.engine.AbstractFunctionFactoryTest;
import io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory;
import io.questdb.std.Numbers;
import io.questdb.std.NumericException;
import io.questdb.std.microtime.DateFormatUtils;
......@@ -39,7 +40,7 @@ public class ToCharTimestampVCFunctionFactoryTest extends AbstractFunctionFactor
@Test
public void testNullFormat() {
assertFailure(11, "format must not be null", 0L, null);
assertFailure(10, "format must not be null", 0L, null);
}
@Test
......@@ -50,7 +51,7 @@ public class ToCharTimestampVCFunctionFactoryTest extends AbstractFunctionFactor
@Override
protected FunctionFactory getFunctionFactory() {
return new ToCharTimestampFunctionFactory();
return new ToStrTimestampFunctionFactory();
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册