Skip to content

Commit 76a2950

Browse files
committed
Polishing.
Inherit column name when using function builder. See #1504
1 parent c61f305 commit 76a2950

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/query/Columns.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public Columns include(CqlIdentifier columnName) {
134134
* @return a new {@link Columns} object containing all column definitions and the TTL for {@code columnName}.
135135
*/
136136
public Columns ttl(String columnName) {
137-
return select(columnName, SelectorBuilder::ttl);
137+
return select(columnName, FunctionCall.from("TTL", ColumnSelector.from(columnName)));
138138
}
139139

140140
/**
@@ -145,7 +145,7 @@ public Columns ttl(String columnName) {
145145
* @return a new {@link Columns} object containing all column definitions and the TTL for {@code columnName}.
146146
*/
147147
public Columns ttl(CqlIdentifier columnName) {
148-
return select(columnName, SelectorBuilder::ttl);
148+
return select(columnName, FunctionCall.from("TTL", ColumnSelector.from(columnName)));
149149
}
150150

151151
/**
@@ -161,7 +161,8 @@ public Columns select(String columnName, Selector selector) {
161161

162162
/**
163163
* Include column {@code columnName} with a built {@link Selector}. This column selection overrides an existing
164-
* selection for the column name.
164+
* selection for the column name. {@link SelectorBuilder} uses the given {@code columnName} as column alias to
165+
* represent the selection in the result.
165166
*
166167
* @param columnName must not be {@literal null}.
167168
* @return a new {@link Columns} object containing all column definitions and the selected {@code columnName}.
@@ -175,7 +176,8 @@ public Columns select(CqlIdentifier columnName, Function<SelectorBuilder, Select
175176

176177
/**
177178
* Include column {@code columnName} with a built {@link Selector}. This column selection overrides an existing
178-
* selection for the column name.
179+
* selection for the column name. {@link SelectorBuilder} uses the given {@code columnName} as column alias to
180+
* represent the selection in the result.
179181
*
180182
* @param columnName must not be {@literal null}.
181183
* @return a new {@link Columns} object containing all column definitions and the selected {@code columnName}.

spring-data-cassandra/src/test/java/org/springframework/data/cassandra/core/StatementFactoryUnitTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ void shouldRenderSimilaritySelector() {
960960
.build(ParameterHandling.BY_NAME);
961961

962962
assertThat(statement.getQuery()).isEqualTo(
963-
"SELECT comment,similarity_cosine(vector,[0.2, 0.15, 0.3, 0.2, 0.05]) FROM withvector ORDER BY vector ANN OF [1.2, 1.3]");
963+
"SELECT comment,similarity_cosine(vector,[0.2, 0.15, 0.3, 0.2, 0.05]) AS vector FROM withvector ORDER BY vector ANN OF [1.2, 1.3]");
964964
assertThat(statement.getNamedValues()).isEmpty();
965965
}
966966

0 commit comments

Comments
 (0)