|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.shardingsphere.infra.binder.engine.segment.dml.expression.type; |
| 19 | + |
| 20 | +import com.cedarsoftware.util.CaseInsensitiveMap; |
| 21 | +import com.cedarsoftware.util.CaseInsensitiveMap.CaseInsensitiveString; |
| 22 | +import com.google.common.collect.LinkedHashMultimap; |
| 23 | +import com.google.common.collect.Multimap; |
| 24 | +import org.apache.shardingsphere.infra.binder.engine.segment.SegmentType; |
| 25 | +import org.apache.shardingsphere.infra.binder.engine.segment.dml.from.context.TableSegmentBinderContext; |
| 26 | +import org.apache.shardingsphere.infra.binder.engine.segment.dml.from.context.type.SimpleTableSegmentBinderContext; |
| 27 | +import org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinderContext; |
| 28 | +import org.apache.shardingsphere.sql.parser.statement.core.enums.TableSourceType; |
| 29 | +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; |
| 30 | +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ColumnProjectionSegment; |
| 31 | +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.join.OuterJoinExpression; |
| 32 | +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; |
| 33 | +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.ColumnSegmentBoundInfo; |
| 34 | +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; |
| 35 | +import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; |
| 36 | +import org.junit.jupiter.api.Test; |
| 37 | + |
| 38 | +import java.util.Collections; |
| 39 | + |
| 40 | +import static org.hamcrest.CoreMatchers.is; |
| 41 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 42 | +import static org.mockito.Mockito.mock; |
| 43 | + |
| 44 | +class OuterJoinExpressionBinderTest { |
| 45 | + |
| 46 | + @Test |
| 47 | + public void assertBindOuterJoinExpression() { |
| 48 | + Multimap<CaseInsensitiveString, TableSegmentBinderContext> tableBinderContexts = LinkedHashMultimap.create(); |
| 49 | + ColumnSegment boundOrderIdColumn = new ColumnSegment(0, 0, new IdentifierValue("order_id")); |
| 50 | + TableSegmentBoundInfo tableBoundInfo = new TableSegmentBoundInfo(new IdentifierValue("t_order"), new IdentifierValue("order_id")); |
| 51 | + boundOrderIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(tableBoundInfo, |
| 52 | + new IdentifierValue("t_order"), new IdentifierValue("order_id"), TableSourceType.PHYSICAL_TABLE)); |
| 53 | + tableBinderContexts.put(new CaseInsensitiveMap.CaseInsensitiveString("t_order"), |
| 54 | + new SimpleTableSegmentBinderContext(Collections.singleton(new ColumnProjectionSegment(boundOrderIdColumn)), TableSourceType.PHYSICAL_TABLE)); |
| 55 | + ColumnSegment column = new ColumnSegment(0, 0, new IdentifierValue("order_id")); |
| 56 | + column.setOwner(new OwnerSegment(0, 0, new IdentifierValue("t_order"))); |
| 57 | + OuterJoinExpression originalExpression = new OuterJoinExpression(0, 0, column, "+", "t_order.order_id(+)"); |
| 58 | + OuterJoinExpression actual = OuterJoinExpressionBinder.bind( |
| 59 | + originalExpression, SegmentType.PREDICATE, mock(SQLStatementBinderContext.class), tableBinderContexts, LinkedHashMultimap.create()); |
| 60 | + assertThat(actual.getStartIndex(), is(originalExpression.getStartIndex())); |
| 61 | + assertThat(actual.getStopIndex(), is(originalExpression.getStopIndex())); |
| 62 | + assertThat(actual.getColumnName().getIdentifier().getValue(), is("order_id")); |
| 63 | + assertThat(actual.getJoinOperator(), is("+")); |
| 64 | + assertThat(actual.getText(), is("t_order.order_id(+)")); |
| 65 | + } |
| 66 | +} |
0 commit comments