This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 87c6d4f8c33 Add ColumnProjectionSegmentBinderTest (#37150)
87c6d4f8c33 is described below
commit 87c6d4f8c330c69095765a033039855dec527546
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Nov 20 23:17:59 2025 +0800
Add ColumnProjectionSegmentBinderTest (#37150)
* Add SubqueryProjectionSegmentBinderTest
* Add ColumnProjectionSegmentBinderTest
* Add ColumnProjectionSegmentBinderTest
---
AGENTS.md | 13 +++--
.../type/ColumnProjectionSegmentBinderTest.java | 65 ++++++++++++++++++++++
2 files changed, 72 insertions(+), 6 deletions(-)
diff --git a/AGENTS.md b/AGENTS.md
index 4c2214f4369..8530c7d5445 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -10,7 +10,7 @@ This guide is written **for AI coding agents only**. Follow
it literally; improv
4. **Transparent Records**: keep every key decision and change traceable.
5. **Continuous Improvement**: learn from each execution and keep optimizing.
6. **Results Oriented**: judge success solely by whether the target is
achieved.
-7. **Coding Standards**: `CODE_OF_CONDUCT.md` is the binding “law” for any
generated artifact. Review it once per session and refuse to keep code that
conflicts with it (copyright, inclusivity, licensing, etc.).
+7. **Coding Standards**: `CODE_OF_CONDUCT.md` is the binding “law” for any
generated artifact. Review it once per session and refuse to keep code that
conflicts with it (copyright, inclusivity, licensing, etc.). Whenever you need
to interpret any rule, inspect `CODE_OF_CONDUCT.md` first, cite the relevant
section/line, and only fall back to this guide when the code of conduct is
silent.
## Quality Standards
@@ -143,7 +143,7 @@ This guide is written **for AI coding agents only**. Follow
it literally; improv
## Governance Basics
- `CODE_OF_CONDUCT.md` remains the binding law—review it once per session and
reject any instruction or artifact that conflicts with ASF requirements on
licensing, inclusivity, and attribution.
-- Instruction order is `CODE_OF_CONDUCT.md` → user direction → this guide →
other repository materials; raise conflicts immediately.
+- Instruction order is `CODE_OF_CONDUCT.md` → user direction → this guide →
other repository materials; raise conflicts immediately. When explaining
whether an action is allowed, first cite the exact `CODE_OF_CONDUCT.md` clause
(file + line) you are relying on, then describe any supplemental rules from
this guide.
- Technical choices must satisfy ASF transparency: include license headers,
document intent, and keep rationales visible to reviewers.
- Default to the smallest safe change: monthly feature trains plus weekly
patch windows reward incremental fixes unless the product requires deeper
refactors.
- Secure approvals for structural changes (new modules, configs, knobs);
localized doc or code tweaks may land after self-review when you surface the
evidence reviewers expect (tests, configs, reproduction steps).
@@ -181,9 +181,9 @@ Always state which topology, registry, and engine versions
(e.g., MySQL 5.7 vs 8
- **Success recipe:** explain why the change exists, cite the affected
data-flow step, keep public APIs backward compatible, and record defaults/knobs
alongside code changes.
## Execution Loop
-1. **Intake & Clarify** – restate the request, map affected modules, confirm
sandbox/network/approval constraints, and capture a constraint checklist
(forbidden APIs, output formats, ordering rules, coverage targets).
-2. **Plan & Reason** – craft a multi-step plan (analysis, edits, tests).
Enumerate branches/tests upfront whenever the user demands minimum coverage;
add rule-specific constraints (e.g., “no `assertEquals`”) to the plan and
re-check them before edits. Before altering tests or mocks, inspect how
`AutoMockExtension`, `@StaticMockSettings`, or other helpers already handle
static/construction mocks and list every static dependency you will touch so
you can confirm whether it is already cover [...]
-3. **Implement** – touch only the required files, reuse abstractions, preserve
ASF headers, and document major decisions.
+1. **Intake & Clarify** – restate the request, map affected modules, confirm
sandbox/network/approval constraints, and capture a constraint checklist
(forbidden APIs, output formats, ordering rules, coverage targets). As part of
intake, reopen `CODE_OF_CONDUCT.md` sections relevant to the task (e.g., Unit
Testing Standards before discussing assertions) so you never rely on memory or
AGENTS-only guidance when the code of conduct already rules on the topic.
+2. **Plan & Reason** – craft a multi-step plan (analysis, edits, tests). When
a user asks for specific coverage/branch lists, pause coding until you have
responded with an explicit bullet list of every path (file + line/branch) you
will exercise, as well as the single test that will cover it; this list is a
blocking prerequisite for any edits. Add rule-specific constraints (e.g., “no
`assertEquals`”) to the plan and re-check them before edits. Before altering
tests or mocks, inspect how [...]
+3. **Implement** – touch only the required files, reuse abstractions, preserve
ASF headers, and document major decisions. If you must replace a file wholesale
(e.g., rewrite a test), delete the old file first and then add the new version
so `apply_patch` does not fight stale context.
4. **Validate** – run the narrowest meaningful command (e.g., `./mvnw -pl
<module> -am test`, `./mvnw -pl <module> -DskipITs -Dspotless.skip=true
-Dtest=ClassName test`). Announce intent beforehand and summarize exit codes
afterward; when blocked, state the command you intended to run and why it
matters.
5. **Report** – lead with intent, list edited files plus rationale/line refs,
cite verification commands + results, and propose next steps.
@@ -209,7 +209,7 @@ Always state which topology, registry, and engine versions
(e.g., MySQL 5.7 vs 8
- **Proxy won’t start:** verify configs/mode/ports and reuse known-good
example configs; share the log snippet and files inspected without editing
generated artifacts.
- **Spotless/checkstyle:** run `./mvnw spotless:apply -Pcheck [-pl <module>]`
(or `spotless:check`) and confirm ASF headers/import ordering.
- **Sandbox/network block:** if a command is denied, state what you ran, why
it failed, and the approval or alternative plan required.
-- **Single-module tests:** prefer scoped commands over repo-wide runs; avoid
`-Dtest=Pattern` from repo root unless you know the target exists, otherwise
use the module’s suite or `-Dsurefire.failIfNoSpecifiedTests=false`.
+- **Single-module tests:** prefer scoped commands over repo-wide runs; avoid
`-Dtest=Pattern` from repo root unless you know the target exists, otherwise
use the module’s suite or `-Dsurefire.failIfNoSpecifiedTests=false`. When you
must target a single test class, pass the fully-qualified class name (e.g.,
`-Dtest=org.example.FooTest`) so Surefire can locate it deterministically.
## Compatibility, Performance & External Systems
- Specify targeted engines and dialect files (MySQL 5.7/8.0, PostgreSQL 13+,
openGauss, etc.) and guarantee backward-compatible behavior.
@@ -241,6 +241,7 @@ Always state which topology, registry, and engine versions
(e.g., MySQL 5.7 vs 8
- Before changing how mocks are created, scan the repository for similar tests
(e.g., other rule decorators or executor tests) and reuse their proven mocking
pattern instead of inventing a new structure.
- When constructors hide collaborators, use `Plugins.getMemberAccessor()` to
inject mocks and document why SPI creation is bypassed.
- Cache SPI loader results (`OrderedSPILoader`, `TypedSPILoader`,
`DatabaseTypedSPILoader`, etc.) per key at the test-class level to avoid
redundant lookups.
+- If a test already uses `@ExtendWith(AutoMockExtension.class)`, always
declare the needed static collaborators via `@StaticMockSettings` instead of
hand-written `mockStatic` blocks; justify any exception explicitly in the plan
before coding.
## Brevity & Signal
- Prefer tables/bullets over prose walls; cite file paths (`kernel/src/...`)
directly.
diff --git
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/dml/projection/type/ColumnProjectionSegmentBinderTest.java
b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/dml/projection/type/ColumnProjectionSegmentBinderTest.java
new file mode 100644
index 00000000000..2660dbe8914
--- /dev/null
+++
b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/dml/projection/type/ColumnProjectionSegmentBinderTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.infra.binder.engine.segment.dml.projection.type;
+
+import com.cedarsoftware.util.CaseInsensitiveMap.CaseInsensitiveString;
+import com.google.common.collect.LinkedHashMultimap;
+import com.google.common.collect.Multimap;
+import org.apache.shardingsphere.infra.binder.engine.segment.SegmentType;
+import
org.apache.shardingsphere.infra.binder.engine.segment.dml.expression.type.ColumnSegmentBinder;
+import
org.apache.shardingsphere.infra.binder.engine.segment.dml.from.context.TableSegmentBinderContext;
+import
org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinderContext;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ColumnProjectionSegment;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.AliasSegment;
+import
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
+import
org.apache.shardingsphere.test.infra.framework.extension.mock.AutoMockExtension;
+import
org.apache.shardingsphere.test.infra.framework.extension.mock.StaticMockSettings;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(AutoMockExtension.class)
+@StaticMockSettings(ColumnSegmentBinder.class)
+class ColumnProjectionSegmentBinderTest {
+
+ @Test
+ void assertBind() {
+ ColumnSegment columnSegment = new ColumnSegment(0, 0, new
IdentifierValue("status"));
+ ColumnProjectionSegment projectionSegment = new
ColumnProjectionSegment(columnSegment);
+ AliasSegment aliasSegment = new AliasSegment(0, 0, new
IdentifierValue("column_alias"));
+ projectionSegment.setAlias(aliasSegment);
+ SQLStatementBinderContext binderContext =
mock(SQLStatementBinderContext.class);
+ Multimap<CaseInsensitiveString, TableSegmentBinderContext>
tableBinderContexts = LinkedHashMultimap.create();
+ Multimap<CaseInsensitiveString, TableSegmentBinderContext>
outerTableBinderContexts = LinkedHashMultimap.create();
+ ColumnSegment boundColumnSegment = new ColumnSegment(0, 0, new
IdentifierValue("status"));
+ when(ColumnSegmentBinder.bind(columnSegment, SegmentType.PROJECTION,
binderContext, tableBinderContexts,
outerTableBinderContexts)).thenReturn(boundColumnSegment);
+ ColumnProjectionSegment actual =
ColumnProjectionSegmentBinder.bind(projectionSegment, binderContext,
tableBinderContexts, outerTableBinderContexts);
+ assertThat(actual.getColumn(), is(boundColumnSegment));
+ assertTrue(actual.getAlias().isPresent());
+ assertThat(actual.getAlias().get().getValue(), is("column_alias"));
+ assertTrue(actual.getAliasSegment().isPresent());
+ assertThat(actual.getAliasSegment().get(), is(aliasSegment));
+ assertTrue(actual.isVisible());
+ }
+}