You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/10/13 00:22:12 UTC
[shardingsphere] branch master updated: Add ColumnExtractorTest (#21532)
This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new ece2727e502 Add ColumnExtractorTest (#21532)
ece2727e502 is described below
commit ece2727e5020c238b47aa5ece726a3a794a74511
Author: klurpicolo <31...@users.noreply.github.com>
AuthorDate: Thu Oct 13 07:22:03 2022 +0700
Add ColumnExtractorTest (#21532)
---
.../sql/common/util/ColumnExtractorTest.java | 57 ++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/sql-parser/statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/ColumnExtractorTest.java b/sql-parser/statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/ColumnExtractorTest.java
new file mode 100644
index 00000000000..ef5321d3dfd
--- /dev/null
+++ b/sql-parser/statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/ColumnExtractorTest.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sql.parser.sql.common.util;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.LiteralExpressionSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
+import org.junit.Test;
+
+public final class ColumnExtractorTest {
+
+ @Test
+ public void assertExtractColumnSegments() {
+ ColumnSegment nameCol = new ColumnSegment(10, 13, new IdentifierValue("name"));
+ ColumnSegment pwnCol = new ColumnSegment(30, 32, new IdentifierValue("pwd"));
+ List<WhereSegment> wheres = Collections.singletonList(createWhereSegment(nameCol, pwnCol));
+ List<ColumnSegment> columnSegments = new ArrayList<>();
+ ColumnExtractor.extractColumnSegments(columnSegments, wheres);
+ assertThat(columnSegments.size(), is(2));
+ Iterator<ColumnSegment> iterator = columnSegments.iterator();
+ assertThat(iterator.next(), is(nameCol));
+ assertThat(iterator.next(), is(pwnCol));
+ }
+
+ private static WhereSegment createWhereSegment(final ColumnSegment col1, final ColumnSegment col2) {
+ BinaryOperationExpression nameExpression = new BinaryOperationExpression(10, 24,
+ col1, new LiteralExpressionSegment(18, 22, "LiLei"), "=", "name = 'LiLei'");
+ BinaryOperationExpression pwdExpression = new BinaryOperationExpression(30, 44,
+ col2, new LiteralExpressionSegment(40, 45, "123456"), "=", "pwd = '123456'");
+ return new WhereSegment(0, 0, new BinaryOperationExpression(0, 0, nameExpression, pwdExpression, "AND", "name = 'LiLei' AND pwd = '123456'"));
+ }
+}