Skip to content

Commit

Permalink
Rename TypeOf to be a part of SystemFunctions.
Browse files Browse the repository at this point in the history
Signed-off-by: Yury-Fridlyand <yuryf@bitquilltech.com>
  • Loading branch information
Yury-Fridlyand committed Oct 19, 2022
1 parent 725f392 commit 27a83e9
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import org.opensearch.sql.expression.operator.arthmetic.ArithmeticFunction;
import org.opensearch.sql.expression.operator.arthmetic.MathematicalFunction;
import org.opensearch.sql.expression.operator.convert.TypeCastOperator;
import org.opensearch.sql.expression.operator.convert.TypeOfOperator;
import org.opensearch.sql.expression.operator.predicate.BinaryPredicateOperator;
import org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperator;
import org.opensearch.sql.expression.system.SystemFunctions;
import org.opensearch.sql.expression.text.TextFunction;
import org.opensearch.sql.expression.window.WindowFunctions;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -46,7 +46,7 @@ public BuiltinFunctionRepository functionRepository() {
WindowFunctions.register(builtinFunctionRepository);
TextFunction.register(builtinFunctionRepository);
TypeCastOperator.register(builtinFunctionRepository);
TypeOfOperator.register(builtinFunctionRepository);
SystemFunctions.register(builtinFunctionRepository);
OpenSearchFunctions.register(builtinFunctionRepository);
return builtinFunctionRepository;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.sql.expression.operator.convert;
package org.opensearch.sql.expression.system;

import static org.opensearch.sql.data.type.ExprCoreType.STRING;

Expand All @@ -23,7 +23,7 @@
import org.opensearch.sql.expression.function.FunctionSignature;

@UtilityClass
public class TypeOfOperator {
public class SystemFunctions {
/**
* Register TypeOf Operator.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.sql.expression.operator.convert;
package org.opensearch.sql.expression.system;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.opensearch.sql.data.type.ExprCoreType.STRING;
Expand Down Expand Up @@ -40,7 +40,7 @@
import org.opensearch.sql.expression.DSL;
import org.opensearch.sql.expression.config.ExpressionConfig;

public class TypeOfOperatorTest {
public class SystemFunctionsTest {
private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository());

@Test
Expand Down
50 changes: 0 additions & 50 deletions integ-test/src/test/java/org/opensearch/sql/ppl/DataTypeIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import static org.opensearch.sql.legacy.SQLIntegTestCase.Index.DATA_TYPE_NUMERIC;
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DATATYPE_NONNUMERIC;
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DATATYPE_NUMERIC;
import static org.opensearch.sql.util.MatcherUtils.rows;
import static org.opensearch.sql.util.MatcherUtils.schema;
import static org.opensearch.sql.util.MatcherUtils.verifyDataRows;
import static org.opensearch.sql.util.MatcherUtils.verifySchema;

import java.io.IOException;
Expand Down Expand Up @@ -74,52 +72,4 @@ public void test_long_integer_data_type() throws IOException {
schema("long1", "long"),
schema("long2", "long"));
}

@Test
public void typeof_sql_types() throws IOException {
JSONObject response = executeQuery(String.format("source=%s | eval "
+ "`str` = typeof('pewpew'), `double` = typeof(1.0),"
+ "`int` = typeof(12345), `long` = typeof(1234567891011), `interval` = typeof(INTERVAL 2 DAY)"
+ " | fields `str`, `double`, `int`, `long`, `interval`",
TEST_INDEX_DATATYPE_NUMERIC));
// TODO: test null in PPL
verifyDataRows(response,
rows("STRING", "DOUBLE", "INTEGER", "LONG", "INTERVAL"));

response = executeQuery(String.format("source=%s | eval "
+ "`timestamp` = typeof(CAST('1961-04-12 09:07:00' AS TIMESTAMP)),"
+ "`time` = typeof(CAST('09:07:00' AS TIME)),"
+ "`date` = typeof(CAST('1961-04-12' AS DATE)),"
+ "`datetime` = typeof(DATETIME('1961-04-12 09:07:00'))"
+ " | fields `timestamp`, `time`, `date`, `datetime`",
TEST_INDEX_DATATYPE_NUMERIC));
verifyDataRows(response,
rows("TIMESTAMP", "TIME", "DATE", "DATETIME"));
}

@Test
public void typeof_opensearch_types() throws IOException {
JSONObject response = executeQuery(String.format("source=%s | eval "
+ "`double` = typeof(double_number), `long` = typeof(long_number),"
+ "`integer` = typeof(integer_number), `byte` = typeof(byte_number),"
+ "`short` = typeof(short_number), `float` = typeof(float_number),"
+ "`half_float` = typeof(half_float_number), `scaled_float` = typeof(scaled_float_number)"
+ " | fields `double`, `long`, `integer`, `byte`, `short`, `float`, `half_float`, `scaled_float`",
TEST_INDEX_DATATYPE_NUMERIC));
verifyDataRows(response,
rows("DOUBLE", "LONG", "INTEGER", "BYTE", "SHORT", "FLOAT", "FLOAT", "DOUBLE"));

response = executeQuery(String.format("source=%s | eval "
+ "`text` = typeof(text_value), `date` = typeof(date_value),"
+ "`boolean` = typeof(boolean_value), `object` = typeof(object_value),"
+ "`keyword` = typeof(keyword_value), `ip` = typeof(ip_value),"
+ "`binary` = typeof(binary_value), `geo_point` = typeof(geo_point_value)"
// TODO activate this test once `ARRAY` type supported, see ExpressionAnalyzer::isTypeNotSupported
//+ ", `nested` = typeof(nested_value)"
+ " | fields `text`, `date`, `boolean`, `object`, `keyword`, `ip`, `binary`, `geo_point`",
TEST_INDEX_DATATYPE_NONNUMERIC));
verifyDataRows(response,
rows("OPENSEARCH_TEXT", "TIMESTAMP", "BOOLEAN", "STRUCT", "STRING",
"OPENSEARCH_IP", "OPENSEARCH_BINARY", "OPENSEARCH_GEO_POINT"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.sql.ppl;

import static org.opensearch.sql.legacy.SQLIntegTestCase.Index.DATA_TYPE_NONNUMERIC;
import static org.opensearch.sql.legacy.SQLIntegTestCase.Index.DATA_TYPE_NUMERIC;
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DATATYPE_NONNUMERIC;
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DATATYPE_NUMERIC;
import static org.opensearch.sql.util.MatcherUtils.rows;
import static org.opensearch.sql.util.MatcherUtils.verifyDataRows;

import java.io.IOException;
import org.json.JSONObject;
import org.junit.Test;

public class SystemFunctionIT extends PPLIntegTestCase {

@Override
public void init() throws IOException {
loadIndex(DATA_TYPE_NUMERIC);
loadIndex(DATA_TYPE_NONNUMERIC);
}

@Test
public void typeof_sql_types() throws IOException {
JSONObject response = executeQuery(String.format("source=%s | eval "
+ "`str` = typeof('pewpew'), `double` = typeof(1.0),"
+ "`int` = typeof(12345), `long` = typeof(1234567891011), `interval` = typeof(INTERVAL 2 DAY)"
+ " | fields `str`, `double`, `int`, `long`, `interval`",
TEST_INDEX_DATATYPE_NUMERIC));
// TODO: test null in PPL
verifyDataRows(response,
rows("STRING", "DOUBLE", "INTEGER", "LONG", "INTERVAL"));

response = executeQuery(String.format("source=%s | eval "
+ "`timestamp` = typeof(CAST('1961-04-12 09:07:00' AS TIMESTAMP)),"
+ "`time` = typeof(CAST('09:07:00' AS TIME)),"
+ "`date` = typeof(CAST('1961-04-12' AS DATE)),"
+ "`datetime` = typeof(DATETIME('1961-04-12 09:07:00'))"
+ " | fields `timestamp`, `time`, `date`, `datetime`",
TEST_INDEX_DATATYPE_NUMERIC));
verifyDataRows(response,
rows("TIMESTAMP", "TIME", "DATE", "DATETIME"));
}

@Test
public void typeof_opensearch_types() throws IOException {
JSONObject response = executeQuery(String.format("source=%s | eval "
+ "`double` = typeof(double_number), `long` = typeof(long_number),"
+ "`integer` = typeof(integer_number), `byte` = typeof(byte_number),"
+ "`short` = typeof(short_number), `float` = typeof(float_number),"
+ "`half_float` = typeof(half_float_number), `scaled_float` = typeof(scaled_float_number)"
+ " | fields `double`, `long`, `integer`, `byte`, `short`, `float`, `half_float`, `scaled_float`",
TEST_INDEX_DATATYPE_NUMERIC));
verifyDataRows(response,
rows("DOUBLE", "LONG", "INTEGER", "BYTE", "SHORT", "FLOAT", "FLOAT", "DOUBLE"));

response = executeQuery(String.format("source=%s | eval "
+ "`text` = typeof(text_value), `date` = typeof(date_value),"
+ "`boolean` = typeof(boolean_value), `object` = typeof(object_value),"
+ "`keyword` = typeof(keyword_value), `ip` = typeof(ip_value),"
+ "`binary` = typeof(binary_value), `geo_point` = typeof(geo_point_value)"
// TODO activate this test once `ARRAY` type supported, see ExpressionAnalyzer::isTypeNotSupported
//+ ", `nested` = typeof(nested_value)"
+ " | fields `text`, `date`, `boolean`, `object`, `keyword`, `ip`, `binary`, `geo_point`",
TEST_INDEX_DATATYPE_NONNUMERIC));
verifyDataRows(response,
rows("OPENSEARCH_TEXT", "TIMESTAMP", "BOOLEAN", "STRUCT", "STRING",
"OPENSEARCH_IP", "OPENSEARCH_BINARY", "OPENSEARCH_GEO_POINT"));
}
}

0 comments on commit 27a83e9

Please sign in to comment.