Skip to content

Commit cabb749

Browse files
author
Lukas Wegmann
authored
SQL: Deprecate index_include_frozen request parameter and FROZEN keyword (#83943) (#84298)
Resolves #81939 (part of #70192) Deprecates the `index_include_frozen` REST parameter in the `/_sql` endpoint and all the syntax including the `FROZEN` keyword. # Conflicts: # x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/parser/LogicalPlanBuilder.java
1 parent 472a5ed commit cabb749

File tree

10 files changed

+201
-5
lines changed

10 files changed

+201
-5
lines changed

docs/changelog/83943.yaml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
pr: 83943
2+
summary: Deprecate `index_include_frozen` request parameter
3+
area: SQL
4+
type: deprecation
5+
issues:
6+
- 81939
7+
deprecation:
8+
title: Deprecate `index_include_frozen` request parameter in `_sql` API
9+
area: REST API
10+
details: |-
11+
Following the deprecation of frozen indices, the `index_include_frozen`
12+
parameter and `FROZEN` syntax is now also deprecated.
13+
impact: |-
14+
You should unfreeze frozen indices using the
15+
{ref}/unfreeze-index-api.html[unfreeze index API] and stop using the
16+
`index_include_frozen` parameter or the `FROZEN` keyword in SQL
17+
queries. For some use cases, the frozen tier may be a suitable
18+
replacement for frozen indices. See {ref}/data-tiers.html[data tiers]
19+
for more information.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.sql.qa.jdbc.security;
9+
10+
import org.elasticsearch.common.settings.Settings;
11+
import org.elasticsearch.xpack.sql.qa.jdbc.JdbcWarningsTestCase;
12+
13+
import java.util.Properties;
14+
15+
public class JdbcWarningsIT extends JdbcWarningsTestCase {
16+
17+
@Override
18+
protected Settings restClientSettings() {
19+
return JdbcConnectionIT.securitySettings();
20+
}
21+
22+
@Override
23+
protected String getProtocol() {
24+
return JdbcConnectionIT.SSL_ENABLED ? "https" : "http";
25+
}
26+
27+
@Override
28+
protected Properties connectionProperties() {
29+
Properties properties = super.connectionProperties();
30+
properties.putAll(JdbcSecurityUtils.adminProperties());
31+
return properties;
32+
}
33+
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.sql.qa.jdbc.single_node;
9+
10+
import org.elasticsearch.xpack.sql.qa.jdbc.JdbcWarningsTestCase;
11+
12+
public class JdbcWarningsIT extends JdbcWarningsTestCase {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.sql.qa.jdbc;
9+
10+
import java.sql.Connection;
11+
import java.sql.ResultSet;
12+
import java.sql.Statement;
13+
14+
public abstract class JdbcWarningsTestCase extends JdbcIntegrationTestCase {
15+
16+
public void testDeprecationWarningsDoNotReachJdbcDriver() throws Exception {
17+
index("test_data", b -> b.field("foo", 1));
18+
19+
try (Connection connection = esJdbc(); Statement statement = connection.createStatement()) {
20+
ResultSet rs = statement.executeQuery("SELECT * FROM FROZEN \"test_*\"");
21+
assertNull(rs.getWarnings());
22+
}
23+
}
24+
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.sql.qa.single_node;
9+
10+
import org.apache.http.entity.ContentType;
11+
import org.apache.http.entity.StringEntity;
12+
import org.elasticsearch.client.Request;
13+
import org.elasticsearch.xpack.sql.qa.rest.BaseRestSqlTestCase;
14+
15+
import java.io.IOException;
16+
17+
import static org.elasticsearch.xpack.sql.qa.rest.RestSqlTestCase.SQL_QUERY_REST_ENDPOINT;
18+
19+
public class RestSqlDeprecationIT extends BaseRestSqlTestCase {
20+
21+
public void testIndexIncludeParameterIsDeprecated() throws IOException {
22+
testDeprecationWarning(
23+
query("SELECT * FROM test").mode(randomMode()).indexIncludeFrozen(randomBoolean()),
24+
"[index_include_frozen] parameter is deprecated because frozen indices have been deprecated. Consider cold or frozen tiers "
25+
+ "in place of frozen indices."
26+
);
27+
}
28+
29+
public void testIncludeFrozenSyntaxIsDeprecatedInShowTables() throws IOException {
30+
testFrozenSyntaxIsDeprecated("SHOW TABLES INCLUDE FROZEN", "INCLUDE FROZEN");
31+
}
32+
33+
public void testIncludeFrozenSyntaxIsDeprecatedInShowColumns() throws IOException {
34+
testFrozenSyntaxIsDeprecated("SHOW COLUMNS INCLUDE FROZEN IN test", "INCLUDE FROZEN");
35+
}
36+
37+
public void testIncludeFrozenSyntaxIsDeprecatedInDescribeTable() throws IOException {
38+
testFrozenSyntaxIsDeprecated("DESCRIBE INCLUDE FROZEN test", "INCLUDE FROZEN");
39+
}
40+
41+
public void testFrozenSyntaxIsDeprecatedInFromClause() throws IOException {
42+
testFrozenSyntaxIsDeprecated("SELECT * FROM FROZEN test", "FROZEN");
43+
}
44+
45+
private void testFrozenSyntaxIsDeprecated(String query, String syntax) throws IOException {
46+
testDeprecationWarning(
47+
query(query).mode(randomMode()),
48+
"["
49+
+ syntax
50+
+ "] syntax is deprecated because frozen indices have been deprecated. "
51+
+ "Consider cold or frozen tiers in place of frozen indices."
52+
);
53+
}
54+
55+
private void testDeprecationWarning(RequestObjectBuilder query, String warning) throws IOException {
56+
index("{\"foo\": 1}");
57+
58+
Request request = new Request("POST", SQL_QUERY_REST_ENDPOINT);
59+
request.setEntity(new StringEntity(query.toString(), ContentType.APPLICATION_JSON));
60+
request.setOptions(expectWarnings(warning));
61+
}
62+
63+
}

x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/BaseRestSqlTestCase.java

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import static org.elasticsearch.xpack.sql.proto.CoreProtocol.FETCH_SIZE_NAME;
3030
import static org.elasticsearch.xpack.sql.proto.CoreProtocol.FIELD_MULTI_VALUE_LENIENCY_NAME;
3131
import static org.elasticsearch.xpack.sql.proto.CoreProtocol.FILTER_NAME;
32+
import static org.elasticsearch.xpack.sql.proto.CoreProtocol.INDEX_INCLUDE_FROZEN_NAME;
3233
import static org.elasticsearch.xpack.sql.proto.CoreProtocol.KEEP_ALIVE_NAME;
3334
import static org.elasticsearch.xpack.sql.proto.CoreProtocol.KEEP_ON_COMPLETION_NAME;
3435
import static org.elasticsearch.xpack.sql.proto.CoreProtocol.MODE_NAME;
@@ -142,6 +143,11 @@ public RequestObjectBuilder runtimeMappings(String runtimeMappings) {
142143
return this;
143144
}
144145

146+
public RequestObjectBuilder indexIncludeFrozen(boolean includeFrozen) {
147+
request.append(field(INDEX_INCLUDE_FROZEN_NAME, includeFrozen));
148+
return this;
149+
}
150+
145151
private static String field(String name, Object value) {
146152
if (value == null) {
147153
return StringUtils.EMPTY;

x-pack/plugin/sql/sql-action/src/main/java/org/elasticsearch/xpack/sql/action/SqlQueryRequest.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
import org.elasticsearch.common.Strings;
1212
import org.elasticsearch.common.io.stream.StreamInput;
1313
import org.elasticsearch.common.io.stream.StreamOutput;
14+
import org.elasticsearch.common.logging.DeprecationCategory;
15+
import org.elasticsearch.common.logging.DeprecationLogger;
1416
import org.elasticsearch.core.TimeValue;
1517
import org.elasticsearch.index.query.QueryBuilder;
1618
import org.elasticsearch.tasks.Task;
1719
import org.elasticsearch.tasks.TaskId;
1820
import org.elasticsearch.xcontent.ObjectParser;
1921
import org.elasticsearch.xcontent.ParseField;
2022
import org.elasticsearch.xcontent.XContentParser;
23+
import org.elasticsearch.xpack.sql.proto.CoreProtocol;
2124
import org.elasticsearch.xpack.sql.proto.RequestInfo;
2225
import org.elasticsearch.xpack.sql.proto.SqlTypedParamValue;
2326

@@ -53,11 +56,21 @@ public class SqlQueryRequest extends AbstractSqlQueryRequest {
5356
static final ParseField KEEP_ON_COMPLETION = new ParseField(KEEP_ON_COMPLETION_NAME);
5457
static final ParseField KEEP_ALIVE = new ParseField(KEEP_ALIVE_NAME);
5558

59+
private static final DeprecationLogger DEPRECATION_LOGGER = DeprecationLogger.getLogger(SqlQueryRequest.class);
60+
61+
private static final String INDEX_INCLUDE_FROZEN_DEPRECATION_MESSAGE = "["
62+
+ CoreProtocol.INDEX_INCLUDE_FROZEN_NAME
63+
+ "] parameter is deprecated because frozen indices have been deprecated. "
64+
+ "Consider cold or frozen tiers in place of frozen indices.";
65+
5666
static {
5767
PARSER.declareString(SqlQueryRequest::cursor, CURSOR);
5868
PARSER.declareBoolean(SqlQueryRequest::columnar, COLUMNAR);
5969
PARSER.declareBoolean(SqlQueryRequest::fieldMultiValueLeniency, FIELD_MULTI_VALUE_LENIENCY);
60-
PARSER.declareBoolean(SqlQueryRequest::indexIncludeFrozen, INDEX_INCLUDE_FROZEN);
70+
PARSER.declareBoolean((r, v) -> {
71+
DEPRECATION_LOGGER.warn(DeprecationCategory.API, "sql_index_include_frozen", INDEX_INCLUDE_FROZEN_DEPRECATION_MESSAGE);
72+
r.indexIncludeFrozen(v);
73+
}, INDEX_INCLUDE_FROZEN);
6174
PARSER.declareBoolean(SqlQueryRequest::binaryCommunication, BINARY_COMMUNICATION);
6275
PARSER.declareField(
6376
SqlQueryRequest::waitForCompletionTimeout,

x-pack/plugin/sql/sql-action/src/test/java/org/elasticsearch/xpack/sql/action/SqlQueryRequestTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected TestSqlQueryRequest createTestInstance() {
7676
randomAlphaOfLength(10),
7777
requestInfo,
7878
randomBoolean(),
79-
randomBoolean(),
79+
false, // deprecated
8080
randomTV(),
8181
randomBoolean(),
8282
randomTVGreaterThan(MIN_KEEP_ALIVE)

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/parser/CommandBuilder.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,17 @@ public Object visitShowFunctions(ShowFunctionsContext ctx) {
120120
public Object visitShowTables(ShowTablesContext ctx) {
121121
TableIdentifier ti = visitTableIdentifier(ctx.tableIdent);
122122
String index = ti != null ? ti.qualifiedIndex() : null;
123+
124+
boolean includeFrozen = ctx.FROZEN() != null;
125+
maybeWarnDeprecatedFrozenSyntax(includeFrozen, "INCLUDE FROZEN");
126+
123127
return new ShowTables(
124128
source(ctx),
125129
visitLikePattern(ctx.clusterLike),
126130
visitString(ctx.cluster),
127131
index,
128132
visitLikePattern(ctx.tableLike),
129-
ctx.FROZEN() != null
133+
includeFrozen
130134
);
131135
}
132136

@@ -139,7 +143,11 @@ public Object visitShowSchemas(ShowSchemasContext ctx) {
139143
public Object visitShowColumns(ShowColumnsContext ctx) {
140144
TableIdentifier ti = visitTableIdentifier(ctx.tableIdent);
141145
String index = ti != null ? ti.qualifiedIndex() : null;
142-
return new ShowColumns(source(ctx), string(ctx.cluster), index, visitLikePattern(ctx.tableLike), ctx.FROZEN() != null);
146+
147+
boolean includeFrozen = ctx.FROZEN() != null;
148+
maybeWarnDeprecatedFrozenSyntax(includeFrozen, "INCLUDE FROZEN");
149+
150+
return new ShowColumns(source(ctx), string(ctx.cluster), index, visitLikePattern(ctx.tableLike), includeFrozen);
143151
}
144152

145153
@Override

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/parser/LogicalPlanBuilder.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import org.antlr.v4.runtime.ParserRuleContext;
1010
import org.antlr.v4.runtime.Token;
1111
import org.antlr.v4.runtime.tree.TerminalNode;
12+
import org.elasticsearch.common.logging.DeprecationCategory;
13+
import org.elasticsearch.common.logging.DeprecationLogger;
1214
import org.elasticsearch.xpack.ql.expression.Alias;
1315
import org.elasticsearch.xpack.ql.expression.Expression;
1416
import org.elasticsearch.xpack.ql.expression.Literal;
@@ -63,11 +65,23 @@
6365
import java.util.Map;
6466

6567
import static java.util.Collections.emptyList;
68+
import static org.elasticsearch.common.logging.LoggerMessageFormat.format;
6669
import static org.elasticsearch.xpack.ql.parser.ParserUtils.source;
6770
import static org.elasticsearch.xpack.ql.parser.ParserUtils.visitList;
6871

6972
abstract class LogicalPlanBuilder extends ExpressionBuilder {
7073

74+
private static final DeprecationLogger DEPRECATION_LOGGER = DeprecationLogger.getLogger(CommandBuilder.class);
75+
76+
private static final String FROZEN_DEPRECATION_WARNING = "[{}] syntax is deprecated because frozen indices have been deprecated. "
77+
+ "Consider cold or frozen tiers in place of frozen indices.";
78+
79+
protected void maybeWarnDeprecatedFrozenSyntax(boolean includeFrozen, String syntax) {
80+
if (includeFrozen) {
81+
DEPRECATION_LOGGER.warn(DeprecationCategory.PARSING, "include_frozen_syntax", format(null, FROZEN_DEPRECATION_WARNING, syntax));
82+
}
83+
}
84+
7185
protected LogicalPlanBuilder(Map<Token, SqlTypedParamValue> params, ZoneId zoneId) {
7286
super(params, zoneId);
7387
}
@@ -267,7 +281,9 @@ public Object visitSubquery(SubqueryContext ctx) {
267281
public LogicalPlan visitTableName(TableNameContext ctx) {
268282
String alias = visitQualifiedName(ctx.qualifiedName());
269283
TableIdentifier tableIdentifier = visitTableIdentifier(ctx.tableIdentifier());
270-
return new UnresolvedRelation(source(ctx), tableIdentifier, alias, ctx.FROZEN() != null);
284+
boolean includeFrozen = ctx.FROZEN() != null;
285+
maybeWarnDeprecatedFrozenSyntax(includeFrozen, "FROZEN");
286+
return new UnresolvedRelation(source(ctx), tableIdentifier, alias, includeFrozen);
271287
}
272288

273289
private Limit limit(LogicalPlan plan, Source source, Token limit) {

0 commit comments

Comments
 (0)