Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[influxdb] Fix for influxdbv1 retention and table names containing keywords or special chars #11139

Merged
merged 4 commits into from
May 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.influxdb.dto.Query;
import org.influxdb.querybuilder.Appender;
import org.influxdb.querybuilder.BuiltQuery;
import org.influxdb.querybuilder.Select;
import org.influxdb.querybuilder.Where;
Expand Down Expand Up @@ -117,10 +116,10 @@ private String calculateTableName(@Nullable String itemName) {

private String fullQualifiedTableName(String retentionPolicy, String tableName, boolean escapeTableName) {
StringBuilder sb = new StringBuilder();
Appender.appendName(retentionPolicy, sb);
sb.append('"').append(retentionPolicy).append('"');
sb.append(".");
if (escapeTableName) {
Appender.appendName(tableName, sb);
sb.append('"').append(tableName).append('"');
} else {
sb.append(tableName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void testSimpleItemQueryWithoutParams() {
FilterCriteria criteria = createBaseCriteria();

String queryV1 = instanceV1.createQuery(criteria, RETENTION_POLICY);
assertThat(queryV1, equalTo("SELECT \"value\"::field,\"item\"::tag FROM origin.sampleItem;"));
assertThat(queryV1, equalTo("SELECT \"value\"::field,\"item\"::tag FROM \"origin\".\"sampleItem\";"));

String queryV2 = instanceV2.createQuery(criteria, RETENTION_POLICY);
assertThat(queryV2,
Expand All @@ -91,7 +91,7 @@ public void testSimpleUnboundedItemWithoutParams() {
criteria.setOrdering(null);

String queryV1 = instanceV1.createQuery(criteria, RETENTION_POLICY);
assertThat(queryV1, equalTo("SELECT \"value\"::field,\"item\"::tag FROM origin./.*/;"));
assertThat(queryV1, equalTo("SELECT \"value\"::field,\"item\"::tag FROM \"origin\"./.*/;"));

String queryV2 = instanceV2.createQuery(criteria, RETENTION_POLICY);
assertThat(queryV2, equalTo("from(bucket:\"origin\")\n\t" + "|> range(start:-100y)"));
Expand All @@ -107,7 +107,7 @@ public void testRangeCriteria() {

String queryV1 = instanceV1.createQuery(criteria, RETENTION_POLICY);
String expectedQueryV1 = String.format(
"SELECT \"value\"::field,\"item\"::tag FROM origin.sampleItem WHERE time >= '%s' AND time <= '%s';",
"SELECT \"value\"::field,\"item\"::tag FROM \"origin\".\"sampleItem\" WHERE time >= '%s' AND time <= '%s';",
now.toInstant(), tomorrow.toInstant());
assertThat(queryV1, equalTo(expectedQueryV1));

Expand All @@ -127,7 +127,8 @@ public void testValueOperator() {
criteria.setState(new PercentType(90));

String query = instanceV1.createQuery(criteria, RETENTION_POLICY);
assertThat(query, equalTo("SELECT \"value\"::field,\"item\"::tag FROM origin.sampleItem WHERE value <= 90;"));
assertThat(query,
equalTo("SELECT \"value\"::field,\"item\"::tag FROM \"origin\".\"sampleItem\" WHERE value <= 90;"));

String queryV2 = instanceV2.createQuery(criteria, RETENTION_POLICY);
assertThat(queryV2,
Expand All @@ -144,7 +145,8 @@ public void testPagination() {
criteria.setPageSize(10);

String query = instanceV1.createQuery(criteria, RETENTION_POLICY);
assertThat(query, equalTo("SELECT \"value\"::field,\"item\"::tag FROM origin.sampleItem LIMIT 10 OFFSET 20;"));
assertThat(query,
equalTo("SELECT \"value\"::field,\"item\"::tag FROM \"origin\".\"sampleItem\" LIMIT 10 OFFSET 20;"));

String queryV2 = instanceV2.createQuery(criteria, RETENTION_POLICY);
assertThat(queryV2, equalTo("from(bucket:\"origin\")\n\t" + "|> range(start:-100y)\n\t"
Expand All @@ -158,7 +160,8 @@ public void testOrdering() {
criteria.setOrdering(FilterCriteria.Ordering.ASCENDING);

String query = instanceV1.createQuery(criteria, RETENTION_POLICY);
assertThat(query, equalTo("SELECT \"value\"::field,\"item\"::tag FROM origin.sampleItem ORDER BY time ASC;"));
assertThat(query,
equalTo("SELECT \"value\"::field,\"item\"::tag FROM \"origin\".\"sampleItem\" ORDER BY time ASC;"));

String queryV2 = instanceV2.createQuery(criteria, RETENTION_POLICY);
assertThat(queryV2,
Expand Down Expand Up @@ -189,7 +192,7 @@ public void testMeasurementNameFromMetadata() {

String queryV1 = instanceV1.createQuery(criteria, RETENTION_POLICY);
assertThat(queryV1, equalTo(
"SELECT \"value\"::field,\"item\"::tag FROM origin.measurementName WHERE item = 'sampleItem';"));
"SELECT \"value\"::field,\"item\"::tag FROM \"origin\".\"measurementName\" WHERE item = 'sampleItem';"));

String queryV2 = instanceV2.createQuery(criteria, RETENTION_POLICY);
assertThat(queryV2,
Expand All @@ -202,7 +205,7 @@ public void testMeasurementNameFromMetadata() {
.thenReturn(new Metadata(metadataKey, "", Map.of("key1", "val1", "key2", "val2")));

queryV1 = instanceV1.createQuery(criteria, RETENTION_POLICY);
assertThat(queryV1, equalTo("SELECT \"value\"::field,\"item\"::tag FROM origin.sampleItem;"));
assertThat(queryV1, equalTo("SELECT \"value\"::field,\"item\"::tag FROM \"origin\".\"sampleItem\";"));

queryV2 = instanceV2.createQuery(criteria, RETENTION_POLICY);
assertThat(queryV2,
Expand Down