|
| 1 | +/* |
| 2 | + * Copyright OpenSearch Contributors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package org.opensearch.sql.opensearch.planner.physical; |
| 7 | + |
| 8 | +import com.google.common.collect.ImmutableMap; |
| 9 | +import org.apache.commons.lang3.tuple.ImmutablePair; |
| 10 | +import org.apache.commons.lang3.tuple.Pair; |
| 11 | +import org.junit.jupiter.api.Test; |
| 12 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 13 | +import org.junit.runner.RunWith; |
| 14 | +import org.mockito.Answers; |
| 15 | +import org.mockito.Mock; |
| 16 | +import org.mockito.MockedStatic; |
| 17 | +import org.mockito.Mockito; |
| 18 | +import org.mockito.junit.MockitoJUnitRunner; |
| 19 | +import org.mockito.junit.jupiter.MockitoExtension; |
| 20 | +import org.mockito.junit.jupiter.MockitoSettings; |
| 21 | +import org.mockito.quality.Strictness; |
| 22 | +import org.opensearch.action.support.PlainActionFuture; |
| 23 | +import org.opensearch.client.node.NodeClient; |
| 24 | +import org.opensearch.ml.client.MachineLearningNodeClient; |
| 25 | +import org.opensearch.ml.common.dataframe.DataFrame; |
| 26 | +import org.opensearch.ml.common.dataframe.DataFrameBuilder; |
| 27 | +import org.opensearch.ml.common.input.MLInput; |
| 28 | +import org.opensearch.ml.common.output.MLOutput; |
| 29 | +import org.opensearch.ml.common.output.MLPredictionOutput; |
| 30 | +import org.opensearch.ml.common.output.MLTrainingOutput; |
| 31 | +import org.opensearch.sql.ast.dsl.AstDSL; |
| 32 | +import org.opensearch.sql.ast.expression.Literal; |
| 33 | +import org.opensearch.sql.data.model.ExprIntegerValue; |
| 34 | +import org.opensearch.sql.data.model.ExprNullValue; |
| 35 | +import org.opensearch.sql.data.model.ExprTupleValue; |
| 36 | +import org.opensearch.sql.data.model.ExprValue; |
| 37 | +import org.opensearch.sql.expression.Expression; |
| 38 | +import org.opensearch.sql.expression.LiteralExpression; |
| 39 | +import org.opensearch.sql.expression.ReferenceExpression; |
| 40 | +import org.opensearch.sql.opensearch.client.MLClient; |
| 41 | +import org.opensearch.sql.opensearch.data.type.OpenSearchTextType; |
| 42 | +import org.opensearch.sql.planner.physical.PhysicalPlan; |
| 43 | +import org.opensearch.sql.planner.physical.PhysicalPlanNodeVisitor; |
| 44 | + |
| 45 | +import java.util.Collections; |
| 46 | +import java.util.HashMap; |
| 47 | +import java.util.List; |
| 48 | +import java.util.Map; |
| 49 | +import java.util.concurrent.TimeUnit; |
| 50 | + |
| 51 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 52 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 53 | +import static org.junit.jupiter.api.Assertions.assertNull; |
| 54 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 55 | +import static org.mockito.ArgumentMatchers.any; |
| 56 | +import static org.mockito.ArgumentMatchers.anyLong; |
| 57 | +import static org.mockito.ArgumentMatchers.eq; |
| 58 | +import static org.mockito.Mockito.when; |
| 59 | +import static org.opensearch.sql.utils.MLCommonsConstants.ACTION; |
| 60 | +import static org.opensearch.sql.utils.MLCommonsConstants.ALGO; |
| 61 | +import static org.opensearch.sql.utils.MLCommonsConstants.KMEANS; |
| 62 | +import static org.opensearch.sql.utils.MLCommonsConstants.PREDICT; |
| 63 | +import static org.opensearch.sql.utils.MLCommonsConstants.TRAIN; |
| 64 | + |
| 65 | +/** |
| 66 | + * To assert the original bahviour of eval operator. |
| 67 | + */ |
| 68 | +@ExtendWith(MockitoExtension.class) |
| 69 | +@MockitoSettings(strictness = Strictness.LENIENT) |
| 70 | +@RunWith(MockitoJUnitRunner.Silent.class) |
| 71 | +public class OpenSearchEvalOperatorTest { |
| 72 | + @Mock private PhysicalPlan input; |
| 73 | + |
| 74 | + @Mock(answer = Answers.RETURNS_DEEP_STUBS) |
| 75 | + private NodeClient nodeClient; |
| 76 | + |
| 77 | + @Test |
| 78 | + public void testOpenSearchEvalAccept() { |
| 79 | + PhysicalPlanNodeVisitor physicalPlanNodeVisitor = |
| 80 | + new PhysicalPlanNodeVisitor<Integer, Object>() {}; |
| 81 | + List<Pair<ReferenceExpression, Expression>> ipAddress = List.of(ImmutablePair.of( |
| 82 | + new ReferenceExpression("ipAddress", OpenSearchTextType.of()), |
| 83 | + new LiteralExpression(ExprNullValue.of()))); |
| 84 | + OpenSearchEvalOperator evalOperator = new OpenSearchEvalOperator(input, ipAddress, nodeClient); |
| 85 | + assertNull(evalOperator.accept(physicalPlanNodeVisitor, null)); |
| 86 | + } |
| 87 | +} |
0 commit comments