Remove duplication in TestExpressionOptimizer
@@ -28,6 +28,8 @@ import com.facebook.presto.sql.relational.RowExpression;
import com.facebook.presto.sql.relational.optimizer.ExpressionOptimizer;
import com.facebook.presto.type.TypeRegistry;
import com.google.common.collect.ImmutableList;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.util.Optional;
@@ -57,11 +59,26 @@ import static org.testng.Assert.assertEquals;
public class TestExpressionOptimizer
{
+ private TypeRegistry typeManager;
+ private ExpressionOptimizer optimizer;
+
+ @BeforeClass
+ public void setUp()
+ {
+ typeManager = new TypeRegistry();
+ optimizer = new ExpressionOptimizer(new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig()), typeManager, TEST_SESSION);
+ }
+
+ @AfterClass(alwaysRun = true)
+ public void tearDown()
+ {
+ typeManager = null;
+ optimizer = null;
+ }
+
@Test(timeOut = 10_000)
public void testPossibleExponentialOptimizationTime()
{
- TypeRegistry typeManager = new TypeRegistry();
- ExpressionOptimizer optimizer = new ExpressionOptimizer(new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig()), typeManager, TEST_SESSION);
RowExpression expression = constant(1L, BIGINT);
for (int i = 0; i < 100; i++) {
Signature signature = internalOperator(OperatorType.ADD.name(), parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT));
@@ -73,9 +90,6 @@ public class TestExpressionOptimizer
@Test
public void testIfConstantOptimization()
{
- TypeRegistry typeManager = new TypeRegistry();
- ExpressionOptimizer optimizer = new ExpressionOptimizer(new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig()), typeManager, TEST_SESSION);
-
assertEquals(optimizer.optimize(ifExpression(constant(true, BOOLEAN), 1L, 2L)), constant(1L, BIGINT));
assertEquals(optimizer.optimize(ifExpression(constant(false, BOOLEAN), 1L, 2L)), constant(2L, BIGINT));
assertEquals(optimizer.optimize(ifExpression(constant(null, BOOLEAN), 1L, 2L)), constant(2L, BIGINT));
@@ -88,8 +102,6 @@ public class TestExpressionOptimizer
@Test
public void testCastWithJsonParseOptimization()
{
- TypeRegistry typeManager = new TypeRegistry();
- ExpressionOptimizer optimizer = new ExpressionOptimizer(new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig()), typeManager, TEST_SESSION);
Signature jsonParseSignature = new Signature("json_parse", SCALAR, JSON.getTypeSignature(), ImmutableList.of(VARCHAR.getTypeSignature()));
// constant
