Skip to content

Commit

Permalink
Cleaned up some code
Browse files Browse the repository at this point in the history
Signed-off-by: Guian Gumpac <guian.gumpac@improving.com>
  • Loading branch information
GumpacG committed Aug 22, 2023
1 parent cc4967b commit 014a31d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ public void select_all_from_subquery() {
}

/**
* Ensure function falls back to legacy engine when used in GROUP BY clause. TODO Remove
* Ensure Nested function falls back to legacy engine when used in GROUP BY clause. TODO Remove
* this test when support is added.
*/
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,4 @@ protected static Environment<Expression, ExprValue> valueEnv() {
}
};
}

protected Environment<Expression, ExprType> typeEnv() {
return typeEnv;
}

protected Function<List<Expression>, FunctionExpression> functionMapping(
BuiltinFunctionName builtinFunctionName) {
switch (builtinFunctionName) {
case ADD:
return (expressions) -> DSL.add(expressions.get(0), expressions.get(1));
case SUBTRACT:
return (expressions) -> DSL.subtract(expressions.get(0), expressions.get(1));
case MULTIPLY:
return (expressions) -> DSL.multiply(expressions.get(0), expressions.get(1));
case DIVIDE:
return (expressions) -> DSL.divide(expressions.get(0), expressions.get(1));
case MODULUS:
return (expressions) -> DSL.modulus(expressions.get(0), expressions.get(1));
default:
throw new RuntimeException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ public class OpenSearchFunctionTest extends ExpressionTestBase {

@Test
void test_opensearch_function() {
// OpenSearchFunction function = mock(OpenSearchFunction.class, withSettings().defaultAnswer(CALLS_REAL_METHODS));
OpenSearchFunction function = new OpenSearchFunction(new FunctionName("match"), List.of(new NamedArgumentExpression("a", new LiteralExpression(new ExprStringValue("a")))));
FunctionExpression expr = function;
// assertEquals("match(field=\"message\", query=\"search query\")", expr.toString());
OpenSearchFunction function = new OpenSearchFunction(
new FunctionName("match"),
List.of(new NamedArgumentExpression("test", new LiteralExpression(new ExprStringValue("test")))));
assertEquals(BOOLEAN, function.type());
assertThrows(UnsupportedOperationException.class,() -> function.valueOf(null));
assertEquals("match(a=\"a\")", function.toString());
assertEquals("match(test=\"test\")", function.toString());
}

// @Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,54 +62,4 @@ public class TestConfig {
.put("comment", ExprCoreType.STRING)
.put("comment.data", ExprCoreType.STRING)
.build();

protected StorageEngine storageEngine() {
return new StorageEngine() {
@Override
public Table getTable(DataSourceSchemaName dataSourceSchemaName, String name) {
return new Table() {
@Override
public boolean exists() {
return true;
}

@Override
public void create(Map<String, ExprType> schema) {
throw new UnsupportedOperationException("Create table is not supported");
}

@Override
public Map<String, ExprType> getFieldTypes() {
return typeMapping;
}

@Override
public PhysicalPlan implement(LogicalPlan plan) {
throw new UnsupportedOperationException();
}
};
}
};
}

protected SymbolTable symbolTable() {
SymbolTable symbolTable = new SymbolTable();
typeMapping.entrySet()
.forEach(
entry -> symbolTable
.store(new Symbol(Namespace.FIELD_NAME, entry.getKey()), entry.getValue()));
return symbolTable;
}

protected Environment<Expression, ExprType> typeEnv() {
return var -> {
if (var instanceof ReferenceExpression) {
ReferenceExpression refExpr = (ReferenceExpression) var;
if (typeMapping.containsKey(refExpr.getAttr())) {
return typeMapping.get(refExpr.getAttr());
}
}
throw new ExpressionEvaluationException("type resolved failed");
};
}
}

0 comments on commit 014a31d

Please sign in to comment.