You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "jacek-lewandowski (via GitHub)" <gi...@apache.org> on 2023/03/06 18:20:52 UTC
[GitHub] [cassandra] jacek-lewandowski opened a new pull request, #2195: Statement source descriptions
jacek-lewandowski opened a new pull request, #2195:
URL: https://github.com/apache/cassandra/pull/2195
Thanks for sending a pull request! Here are some tips if you're new here:
* Ensure you have added or run the [appropriate tests](https://cassandra.apache.org/_/development/testing.html) for your PR.
* Be sure to keep the PR description updated to reflect all changes.
* Write your PR title to summarize what this PR proposes.
* If possible, provide a concise example to reproduce the issue for a faster review.
* Read our [contributor guidelines](https://cassandra.apache.org/_/development/index.html)
* If you're making a documentation change, see our [guide to documentation contribution](https://cassandra.apache.org/_/development/documentation.html)
Commit messages should follow the following format:
```
<One sentence description, usually Jira title or CHANGES.txt summary>
<Optional lengthier description (context on patch)>
patch by <Authors>; reviewed by <Reviewers> for CASSANDRA-#####
Co-authored-by: Name1 <email1>
Co-authored-by: Name2 <email2>
```
The [Cassandra Jira](https://issues.apache.org/jira/projects/CASSANDRA/issues/)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] jacek-lewandowski commented on a diff in pull request #2195: [CASSANDRA-18302] Statement source descriptions
Posted by "jacek-lewandowski (via GitHub)" <gi...@apache.org>.
jacek-lewandowski commented on code in PR #2195:
URL: https://github.com/apache/cassandra/pull/2195#discussion_r1132070976
##########
src/java/org/apache/cassandra/cql3/StatementSource.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.cassandra.cql3;
+
+import java.util.Objects;
+import java.util.regex.Pattern;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import com.google.common.base.Preconditions;
+
+import org.antlr.runtime.Token;
+import org.apache.cassandra.cql3.statements.QualifiedStatement;
+
+public class StatementSource
+{
+ public static final StatementSource INTERNAL = Bounds.INTERNAL.describeSource(null);
+
+ public final String text;
+ public final Bounds bounds;
+
+ public StatementSource(@Nullable String text, @Nonnull Bounds bounds)
+ {
+ Objects.requireNonNull(bounds);
+ this.text = text;
+ this.bounds = bounds;
+ }
+
+ public String describe(boolean mayIncludeSourceText)
+ {
+ if (this == INTERNAL)
+ {
+ return "<<<internal statement>>>";
+ }
+ else
+ {
+ if (bounds != Bounds.INTERNAL && !bounds.isEmpty() && text != null && mayIncludeSourceText)
+ return String.format("at %d:%d - %s", bounds.startLine + 1, bounds.startChar + 1, text);
+ else if (bounds != Bounds.INTERNAL && !bounds.isEmpty())
+ return String.format("at %d:%d", bounds.startLine + 1, bounds.startChar + 1);
+ else if (text != null && !bounds.isEmpty() && mayIncludeSourceText)
+ return String.format("%s", text);
+ else
+ return "";
+ }
+ }
+
+ public static Bounds createBounds(Token startToken, Token endToken)
+ {
+ Objects.requireNonNull(startToken);
+ Objects.requireNonNull(endToken);
+
+ int startLine, startChar, endLine, endChar;
+
+ if (startToken.getType() == Token.EOF)
+ {
+ startLine = Character.MAX_VALUE;
Review Comment:
Yes, we can assume that
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] dcapwell commented on a diff in pull request #2195: [CASSANDRA-18302] Statement source descriptions
Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on code in PR #2195:
URL: https://github.com/apache/cassandra/pull/2195#discussion_r1131885188
##########
src/java/org/apache/cassandra/cql3/StatementSource.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.cassandra.cql3;
+
+import java.util.Objects;
+import java.util.regex.Pattern;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import com.google.common.base.Preconditions;
+
+import org.antlr.runtime.Token;
+import org.apache.cassandra.cql3.statements.QualifiedStatement;
+
+public class StatementSource
+{
+ public static final StatementSource INTERNAL = Bounds.INTERNAL.describeSource(null);
+
+ public final String text;
+ public final Bounds bounds;
+
+ public StatementSource(@Nullable String text, @Nonnull Bounds bounds)
+ {
+ Objects.requireNonNull(bounds);
+ this.text = text;
+ this.bounds = bounds;
+ }
+
+ public String describe(boolean mayIncludeSourceText)
+ {
+ if (this == INTERNAL)
+ {
+ return "<<<internal statement>>>";
+ }
+ else
+ {
+ if (bounds != Bounds.INTERNAL && !bounds.isEmpty() && text != null && mayIncludeSourceText)
+ return String.format("at %d:%d - %s", bounds.startLine + 1, bounds.startChar + 1, text);
+ else if (bounds != Bounds.INTERNAL && !bounds.isEmpty())
+ return String.format("at %d:%d", bounds.startLine + 1, bounds.startChar + 1);
+ else if (text != null && !bounds.isEmpty() && mayIncludeSourceText)
+ return String.format("%s", text);
+ else
+ return "";
+ }
+ }
+
+ public static Bounds createBounds(Token startToken, Token endToken)
+ {
+ Objects.requireNonNull(startToken);
+ Objects.requireNonNull(endToken);
+
+ int startLine, startChar, endLine, endChar;
+
+ if (startToken.getType() == Token.EOF)
+ {
+ startLine = Character.MAX_VALUE;
+ startChar = Character.MAX_VALUE;
+ }
+ else
+ {
+ startLine = Math.min(Math.max(startToken.getLine(), 1) - 1, Character.MAX_VALUE);
+ startChar = Math.min(Math.max(startToken.getCharPositionInLine(), 0), Character.MAX_VALUE);
+ }
+
+ if (endToken.getType() == Token.EOF)
+ {
+ endLine = Character.MAX_VALUE;
+ endChar = Character.MAX_VALUE;
+ }
+ else
+ {
+ endLine = Math.min(Math.max(endToken.getLine(), 1) - 1, Character.MAX_VALUE);
+ endChar = Math.min(Math.max(endToken.getCharPositionInLine(), 0), Character.MAX_VALUE);
+ }
+
+ return new Bounds(startLine, startChar, endLine, endChar);
+ }
+
+ public static class Bounds
+ {
+ public static final Bounds INTERNAL = new Bounds(0, 0, Character.MAX_VALUE, Character.MAX_VALUE);
+
+ private static final Pattern LINE_BREAK = Pattern.compile("\\R");
+ private static final String SEPARATOR = " ";
+
+ private final int startLine;
+ private final int startChar;
+ private final int endLine;
+ private final int endChar;
+
+ private Bounds(int startLine, int startChar, int endLine, int endChar)
+ {
+ Preconditions.checkArgument(startLine >= 0 && startLine <= Character.MAX_VALUE);
+ Preconditions.checkArgument(startChar >= 0 && startChar <= Character.MAX_VALUE);
+ Preconditions.checkArgument(endLine >= 0 && endLine <= Character.MAX_VALUE);
+ Preconditions.checkArgument(endChar >= 0 && endChar <= Character.MAX_VALUE);
+
+ this.startLine = startLine;
+ this.startChar = startChar;
+ this.endLine = endLine;
+ this.endChar = endChar;
+ }
+
+ private boolean isEmpty()
+ {
+ return startLine == Character.MAX_VALUE ||
+ startLine > endLine ||
Review Comment:
what is the case that this happens? this feels like a bug, should we not fail?
##########
src/java/org/apache/cassandra/cql3/StatementSource.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.cassandra.cql3;
+
+import java.util.Objects;
+import java.util.regex.Pattern;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import com.google.common.base.Preconditions;
+
+import org.antlr.runtime.Token;
+import org.apache.cassandra.cql3.statements.QualifiedStatement;
+
+public class StatementSource
+{
+ public static final StatementSource INTERNAL = Bounds.INTERNAL.describeSource(null);
+
+ public final String text;
+ public final Bounds bounds;
+
+ public StatementSource(@Nullable String text, @Nonnull Bounds bounds)
+ {
+ Objects.requireNonNull(bounds);
+ this.text = text;
+ this.bounds = bounds;
+ }
+
+ public String describe(boolean mayIncludeSourceText)
+ {
+ if (this == INTERNAL)
+ {
+ return "<<<internal statement>>>";
+ }
+ else
+ {
+ if (bounds != Bounds.INTERNAL && !bounds.isEmpty() && text != null && mayIncludeSourceText)
+ return String.format("at %d:%d - %s", bounds.startLine + 1, bounds.startChar + 1, text);
+ else if (bounds != Bounds.INTERNAL && !bounds.isEmpty())
+ return String.format("at %d:%d", bounds.startLine + 1, bounds.startChar + 1);
+ else if (text != null && !bounds.isEmpty() && mayIncludeSourceText)
+ return String.format("%s", text);
+ else
+ return "";
+ }
+ }
+
+ public static Bounds createBounds(Token startToken, Token endToken)
+ {
+ Objects.requireNonNull(startToken);
+ Objects.requireNonNull(endToken);
+
+ int startLine, startChar, endLine, endChar;
+
+ if (startToken.getType() == Token.EOF)
+ {
+ startLine = Character.MAX_VALUE;
+ startChar = Character.MAX_VALUE;
+ }
+ else
+ {
+ startLine = Math.min(Math.max(startToken.getLine(), 1) - 1, Character.MAX_VALUE);
+ startChar = Math.min(Math.max(startToken.getCharPositionInLine(), 0), Character.MAX_VALUE);
+ }
+
+ if (endToken.getType() == Token.EOF)
+ {
+ endLine = Character.MAX_VALUE;
+ endChar = Character.MAX_VALUE;
+ }
+ else
+ {
+ endLine = Math.min(Math.max(endToken.getLine(), 1) - 1, Character.MAX_VALUE);
+ endChar = Math.min(Math.max(endToken.getCharPositionInLine(), 0), Character.MAX_VALUE);
+ }
+
+ return new Bounds(startLine, startChar, endLine, endChar);
+ }
+
+ public static class Bounds
+ {
+ public static final Bounds INTERNAL = new Bounds(0, 0, Character.MAX_VALUE, Character.MAX_VALUE);
+
+ private static final Pattern LINE_BREAK = Pattern.compile("\\R");
+ private static final String SEPARATOR = " ";
+
+ private final int startLine;
+ private final int startChar;
+ private final int endLine;
+ private final int endChar;
+
+ private Bounds(int startLine, int startChar, int endLine, int endChar)
+ {
+ Preconditions.checkArgument(startLine >= 0 && startLine <= Character.MAX_VALUE);
+ Preconditions.checkArgument(startChar >= 0 && startChar <= Character.MAX_VALUE);
+ Preconditions.checkArgument(endLine >= 0 && endLine <= Character.MAX_VALUE);
+ Preconditions.checkArgument(endChar >= 0 && endChar <= Character.MAX_VALUE);
+
+ this.startLine = startLine;
+ this.startChar = startChar;
+ this.endLine = endLine;
+ this.endChar = endChar;
+ }
+
+ private boolean isEmpty()
+ {
+ return startLine == Character.MAX_VALUE ||
+ startLine > endLine ||
+ startLine == endLine && (startChar == Character.MAX_VALUE || startChar > endChar);
Review Comment:
`startChar > endChar` feels like a bug
##########
src/java/org/apache/cassandra/cql3/StatementSource.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.cassandra.cql3;
+
+import java.util.Objects;
+import java.util.regex.Pattern;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import com.google.common.base.Preconditions;
+
+import org.antlr.runtime.Token;
+import org.apache.cassandra.cql3.statements.QualifiedStatement;
+
+public class StatementSource
+{
+ public static final StatementSource INTERNAL = Bounds.INTERNAL.describeSource(null);
+
+ public final String text;
+ public final Bounds bounds;
+
+ public StatementSource(@Nullable String text, @Nonnull Bounds bounds)
+ {
+ Objects.requireNonNull(bounds);
+ this.text = text;
+ this.bounds = bounds;
+ }
+
+ public String describe(boolean mayIncludeSourceText)
+ {
+ if (this == INTERNAL)
+ {
+ return "<<<internal statement>>>";
+ }
+ else
+ {
+ if (bounds != Bounds.INTERNAL && !bounds.isEmpty() && text != null && mayIncludeSourceText)
+ return String.format("at %d:%d - %s", bounds.startLine + 1, bounds.startChar + 1, text);
+ else if (bounds != Bounds.INTERNAL && !bounds.isEmpty())
+ return String.format("at %d:%d", bounds.startLine + 1, bounds.startChar + 1);
+ else if (text != null && !bounds.isEmpty() && mayIncludeSourceText)
+ return String.format("%s", text);
+ else
+ return "";
+ }
+ }
+
+ public static Bounds createBounds(Token startToken, Token endToken)
+ {
+ Objects.requireNonNull(startToken);
+ Objects.requireNonNull(endToken);
+
+ int startLine, startChar, endLine, endChar;
+
+ if (startToken.getType() == Token.EOF)
+ {
+ startLine = Character.MAX_VALUE;
Review Comment:
if start token is EOF do we not know that endToken is as well?
##########
src/java/org/apache/cassandra/cql3/statements/DeleteStatement.java:
##########
@@ -174,7 +186,8 @@ protected ModificationStatement prepareInternal(ClientState state,
operations,
restrictions,
conditions,
- attrs);
+ attrs,
+ bounds.describeSource(enclosingStatement));
Review Comment:
this feels backwards, we create the underline statements before we create the composite statement, so how do we pass it in?
##########
src/java/org/apache/cassandra/cql3/statements/TransactionStatement.java:
##########
@@ -223,12 +217,9 @@ TxnNamedRead createNamedRead(NamedSelect namedSelect, QueryOptions options, Clie
List<TxnNamedRead> createNamedReads(NamedSelect namedSelect, QueryOptions options, ClientState state)
{
SelectStatement select = namedSelect.select;
- ReadQuery readQuery = select.getQuery(options, 0);
- checkTrue(readQuery instanceof SinglePartitionReadQuery.Group, ILLEGAL_RANGE_QUERY_MESSAGE, select.asCQL(options, state));
-
// We reject reads from both LET and SELECT that do not specify a single row.
@SuppressWarnings("unchecked")
- SinglePartitionReadQuery.Group<SinglePartitionReadCommand> selectQuery = (SinglePartitionReadQuery.Group<SinglePartitionReadCommand>) readQuery;
+ SinglePartitionReadQuery.Group<SinglePartitionReadCommand> selectQuery = (SinglePartitionReadQuery.Group<SinglePartitionReadCommand>) select.getQuery(options, 0);
Review Comment:
why prefer class cast over `ILLEGAL_RANGE_QUERY_MESSAGE`?
##########
src/java/org/apache/cassandra/cql3/statements/TransactionStatement.java:
##########
@@ -207,12 +204,9 @@ public ResultSet.ResultMetadata getResultMetadata()
TxnNamedRead createNamedRead(NamedSelect namedSelect, QueryOptions options, ClientState state)
{
SelectStatement select = namedSelect.select;
- ReadQuery readQuery = select.getQuery(options, 0);
- checkTrue(readQuery instanceof SinglePartitionReadQuery.Group, ILLEGAL_RANGE_QUERY_MESSAGE, select.asCQL(options, state));
-
// We reject reads from both LET and SELECT that do not specify a single row.
@SuppressWarnings("unchecked")
- SinglePartitionReadQuery.Group<SinglePartitionReadCommand> selectQuery = (SinglePartitionReadQuery.Group<SinglePartitionReadCommand>) readQuery;
+ SinglePartitionReadQuery.Group<SinglePartitionReadCommand> selectQuery = (SinglePartitionReadQuery.Group<SinglePartitionReadCommand>) select.getQuery(options, 0);
Review Comment:
why prefer ClassCast rather than `ILLEGAL_RANGE_QUERY_MESSAGE`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] maedhroz commented on a diff in pull request #2195: [CASSANDRA-18302] Statement source descriptions
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #2195:
URL: https://github.com/apache/cassandra/pull/2195#discussion_r1138094108
##########
src/java/org/apache/cassandra/cql3/statements/TransactionStatement.java:
##########
@@ -366,21 +357,19 @@ public ResultMessage execute(QueryState state, QueryOptions options, long queryS
try
{
+ // check again since now we have query options; note that statements are quaranted to be single partition reads at this point
for (NamedSelect assignment : assignments)
- checkAtMostOneRowSpecified(state.getClientState(), options, assignment.select, INCOMPLETE_PRIMARY_KEY_LET_MESSAGE);
+ checkFalse(isSelectingMultipleClusterings(assignment.select, options), INCOMPLETE_PRIMARY_KEY_SELECT_MESSAGE, "LET assignment", assignment.select.source);
if (returningSelect != null)
- checkAtMostOneRowSpecified(state.getClientState(), options, returningSelect.select, INCOMPLETE_PRIMARY_KEY_SELECT_MESSAGE);
+ checkFalse(isSelectingMultipleClusterings(returningSelect.select, options), INCOMPLETE_PRIMARY_KEY_SELECT_MESSAGE, "returning SELECT", returningSelect.select.source);
Review Comment:
I'd even be fine if we just did what we do for INSERT/UPDATE...that is, just say `SELECT at [2:1]` or `LET at [1:1]`. Not sure if someone reading this would glean information from "returning" or it's just an implementation detail.
CC @dcapwell
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] dcapwell commented on a diff in pull request #2195: [CASSANDRA-18302] Statement source descriptions
Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on code in PR #2195:
URL: https://github.com/apache/cassandra/pull/2195#discussion_r1138096975
##########
src/java/org/apache/cassandra/cql3/statements/TransactionStatement.java:
##########
@@ -366,21 +357,19 @@ public ResultMessage execute(QueryState state, QueryOptions options, long queryS
try
{
+ // check again since now we have query options; note that statements are quaranted to be single partition reads at this point
for (NamedSelect assignment : assignments)
- checkAtMostOneRowSpecified(state.getClientState(), options, assignment.select, INCOMPLETE_PRIMARY_KEY_LET_MESSAGE);
+ checkFalse(isSelectingMultipleClusterings(assignment.select, options), INCOMPLETE_PRIMARY_KEY_SELECT_MESSAGE, "LET assignment", assignment.select.source);
if (returningSelect != null)
- checkAtMostOneRowSpecified(state.getClientState(), options, returningSelect.select, INCOMPLETE_PRIMARY_KEY_SELECT_MESSAGE);
+ checkFalse(isSelectingMultipleClusterings(returningSelect.select, options), INCOMPLETE_PRIMARY_KEY_SELECT_MESSAGE, "returning SELECT", returningSelect.select.source);
Review Comment:
"returning select" I think helps as we can only have 1 of those
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] maedhroz commented on a diff in pull request #2195: [CASSANDRA-18302] Statement source descriptions
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #2195:
URL: https://github.com/apache/cassandra/pull/2195#discussion_r1138094416
##########
test/unit/org/apache/cassandra/cql3/StatementSourceTest.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.cassandra.cql3;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.antlr.runtime.Token;
+import org.mockito.Mockito;
+
+import static org.apache.cassandra.cql3.StatementSource.create;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.when;
+
+public class StatementSourceTest
+{
+ private final static Logger logger = LoggerFactory.getLogger(StatementSourceTest.class);
Review Comment:
logger unused now
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] maedhroz commented on a diff in pull request #2195: [CASSANDRA-18302] Statement source descriptions
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #2195:
URL: https://github.com/apache/cassandra/pull/2195#discussion_r1134681157
##########
src/java/org/apache/cassandra/cql3/statements/QualifiedStatement.java:
##########
@@ -81,13 +81,27 @@ public String toString()
public static abstract class Composite extends QualifiedStatement
{
+ private static final int RAW_TEXT_MAX_LENGTH = 4096;
Review Comment:
If we set this to something lower (let's say 38), and then run `shouldRejectIllegalLimitInLet()`, you encounter a situation where the `Bounds` points to non-existent raw data. I suppose this won't be problematic unless we have very large statements.
In `CQLFragmentParser#parseAnyUnhandled()`, I think we already have the `Bounds` objects we would later use to filter the raw text, right? What if, instead of filtering later, and storing the raw text for the entire enclosing statement, we filter each statement in `CQLFragmentParser#parseAnyUnhandled()` avoiding the need for a limit in the first place? The individual statement would just get the simple bounds and the text from the raw statement text within those bounds...and we'd be able to present the error the same way (I think).
WDYT?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] maedhroz commented on a diff in pull request #2195: [CASSANDRA-18302] Statement source descriptions
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #2195:
URL: https://github.com/apache/cassandra/pull/2195#discussion_r1134593113
##########
src/java/org/apache/cassandra/cql3/statements/QualifiedStatement.java:
##########
@@ -81,13 +81,27 @@ public String toString()
public static abstract class Composite extends QualifiedStatement
{
+ private static final int RAW_TEXT_MAX_LENGTH = 4096;
+
+ private String txt;
+
Composite()
{
super(null);
}
protected abstract Iterable<? extends QualifiedStatement> getStatements();
+ public void setRawText(String txt)
+ {
+ this.txt = txt != null ? txt.substring(0, Math.min(txt.length(), RAW_TEXT_MAX_LENGTH)) : null;
Review Comment:
nit: if we actually do exceed the max length, it might be a nice UX tweak to include a "blah blah..." (ellipsis) at the end just to make it clear there's more content (but we're truncating).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] dcapwell commented on a diff in pull request #2195: [CASSANDRA-18302] Statement source descriptions
Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on code in PR #2195:
URL: https://github.com/apache/cassandra/pull/2195#discussion_r1137382160
##########
src/java/org/apache/cassandra/cql3/StatementSource.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.cassandra.cql3;
+
+import java.util.Objects;
+import java.util.regex.Pattern;
+import javax.annotation.Nullable;
+
+import org.antlr.runtime.Token;
+import org.antlr.runtime.TokenStream;
+
+import static java.lang.Math.max;
+import static java.lang.Math.min;
+
+public class StatementSource
+{
+ public static final StatementSource INTERNAL = new StatementSource(0, 0, null);
+ private static final Pattern TWO_OR_MORE_WHITESPACES = Pattern.compile("\\s{2,}");
+
+ public final int line;
+ public final int charPositionInLine;
+ public final String text;
+
+ public StatementSource(int line, int charPositionInLine, @Nullable String text)
+ {
+ this.line = line;
+ this.charPositionInLine = charPositionInLine;
+ this.text = text;
+ }
+
+ public String describe(boolean mayIncludeSourceText)
+ {
+ if (this == INTERNAL)
+ {
+ return "<<<internal statement>>>";
+ }
+ else
+ {
+ if (!isEmpty() && text != null && mayIncludeSourceText)
+ return String.format("at [%d:%d] - %s", line + 1, charPositionInLine + 1, text);
+ else if (!isEmpty())
+ return String.format("at [%d:%d]", line + 1, charPositionInLine + 1);
+ else
+ return "";
+ }
+ }
+
+ public boolean isEmpty()
+ {
+ return line > Character.MAX_VALUE || line == Character.MAX_VALUE && charPositionInLine > Character.MAX_VALUE;
+ }
+
+ public static StatementSource create(Token startToken, Token endToken, TokenStream input)
+ {
+ Objects.requireNonNull(startToken);
+ Objects.requireNonNull(endToken);
+ Objects.requireNonNull(input);
+
+ if (startToken.getType() == Token.EOF)
+ return new StatementSource(Character.MAX_VALUE + 1, 0, null);
+
+ int startLine = min(max(startToken.getLine(), 1) - 1, Character.MAX_VALUE);
+ int startChar = min(max(startToken.getCharPositionInLine(), 0), Character.MAX_VALUE);
+ String txt = input.toString(startToken, endToken);
+ txt = txt.replace('\n', ' ');
+ txt = TWO_OR_MORE_WHITESPACES.matcher(txt).replaceAll(" ").trim();
Review Comment:
we should leave the input alone, if we want to show the string the users provided, we should show as-is
##########
src/java/org/apache/cassandra/cql3/StatementSource.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.cassandra.cql3;
+
+import java.util.Objects;
+import java.util.regex.Pattern;
+import javax.annotation.Nullable;
+
+import org.antlr.runtime.Token;
+import org.antlr.runtime.TokenStream;
+
+import static java.lang.Math.max;
+import static java.lang.Math.min;
+
+public class StatementSource
+{
+ public static final StatementSource INTERNAL = new StatementSource(0, 0, null);
+ private static final Pattern TWO_OR_MORE_WHITESPACES = Pattern.compile("\\s{2,}");
+
+ public final int line;
+ public final int charPositionInLine;
+ public final String text;
+
+ public StatementSource(int line, int charPositionInLine, @Nullable String text)
+ {
+ this.line = line;
+ this.charPositionInLine = charPositionInLine;
+ this.text = text;
+ }
+
+ public String describe(boolean mayIncludeSourceText)
+ {
+ if (this == INTERNAL)
+ {
+ return "<<<internal statement>>>";
+ }
+ else
+ {
+ if (!isEmpty() && text != null && mayIncludeSourceText)
+ return String.format("at [%d:%d] - %s", line + 1, charPositionInLine + 1, text);
+ else if (!isEmpty())
+ return String.format("at [%d:%d]", line + 1, charPositionInLine + 1);
+ else
+ return "";
+ }
+ }
+
+ public boolean isEmpty()
+ {
+ return line > Character.MAX_VALUE || line == Character.MAX_VALUE && charPositionInLine > Character.MAX_VALUE;
+ }
+
+ public static StatementSource create(Token startToken, Token endToken, TokenStream input)
+ {
+ Objects.requireNonNull(startToken);
+ Objects.requireNonNull(endToken);
+ Objects.requireNonNull(input);
+
+ if (startToken.getType() == Token.EOF)
+ return new StatementSource(Character.MAX_VALUE + 1, 0, null);
+
+ int startLine = min(max(startToken.getLine(), 1) - 1, Character.MAX_VALUE);
+ int startChar = min(max(startToken.getCharPositionInLine(), 0), Character.MAX_VALUE);
+ String txt = input.toString(startToken, endToken);
+ txt = txt.replace('\n', ' ');
Review Comment:
we should keep the newline,
```
SELECT a,
b,
c -- should fail at line 3 due to 3 not being in the schema
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] jacek-lewandowski commented on pull request #2195: [CASSANDRA-18302] Statement source descriptions
Posted by "jacek-lewandowski (via GitHub)" <gi...@apache.org>.
jacek-lewandowski commented on PR #2195:
URL: https://github.com/apache/cassandra/pull/2195#issuecomment-1463472455
thanks @dcapwell, I've applied some fixes basing on your feedback
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] maedhroz commented on a diff in pull request #2195: [CASSANDRA-18302] Statement source descriptions
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #2195:
URL: https://github.com/apache/cassandra/pull/2195#discussion_r1138098183
##########
src/java/org/apache/cassandra/cql3/statements/TransactionStatement.java:
##########
@@ -366,21 +357,19 @@ public ResultMessage execute(QueryState state, QueryOptions options, long queryS
try
{
+ // check again since now we have query options; note that statements are quaranted to be single partition reads at this point
for (NamedSelect assignment : assignments)
- checkAtMostOneRowSpecified(state.getClientState(), options, assignment.select, INCOMPLETE_PRIMARY_KEY_LET_MESSAGE);
+ checkFalse(isSelectingMultipleClusterings(assignment.select, options), INCOMPLETE_PRIMARY_KEY_SELECT_MESSAGE, "LET assignment", assignment.select.source);
if (returningSelect != null)
- checkAtMostOneRowSpecified(state.getClientState(), options, returningSelect.select, INCOMPLETE_PRIMARY_KEY_SELECT_MESSAGE);
+ checkFalse(isSelectingMultipleClusterings(returningSelect.select, options), INCOMPLETE_PRIMARY_KEY_SELECT_MESSAGE, "returning SELECT", returningSelect.select.source);
Review Comment:
The only other SELECTs would be called LET here...anyway...I'm good with whatever the two of you like better.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] maedhroz commented on a diff in pull request #2195: [CASSANDRA-18302] Statement source descriptions
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #2195:
URL: https://github.com/apache/cassandra/pull/2195#discussion_r1134685343
##########
src/java/org/apache/cassandra/cql3/StatementSource.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.cassandra.cql3;
+
+import java.util.Objects;
+import java.util.regex.Pattern;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import com.google.common.base.Preconditions;
+
+import org.antlr.runtime.Token;
+import org.apache.cassandra.cql3.statements.QualifiedStatement;
+
+import static java.lang.Math.max;
+import static java.lang.Math.min;
+
+public class StatementSource
+{
+ public static final StatementSource INTERNAL = Bounds.EMPTY.describeSource(null);
+
+ public final String text;
+ public final Bounds bounds;
+
+ public StatementSource(@Nullable String text, @Nonnull Bounds bounds)
+ {
+ Objects.requireNonNull(bounds);
+ this.text = text;
+ this.bounds = bounds;
+ }
+
+ public String describe(boolean mayIncludeSourceText)
+ {
+ if (this == INTERNAL)
+ {
+ return "<<<internal statement>>>";
+ }
+ else
+ {
+ if (!bounds.isEmpty() && text != null && mayIncludeSourceText)
+ return String.format("at %d:%d - %s", bounds.startLine + 1, bounds.startChar + 1, text);
Review Comment:
nit: Another way to do it that could avoid the dash...
`at [2:1] SELECT....`
Matter of style though, so feel free to ignore.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] jacek-lewandowski commented on a diff in pull request #2195: [CASSANDRA-18302] Statement source descriptions
Posted by "jacek-lewandowski (via GitHub)" <gi...@apache.org>.
jacek-lewandowski commented on code in PR #2195:
URL: https://github.com/apache/cassandra/pull/2195#discussion_r1132071739
##########
src/java/org/apache/cassandra/cql3/statements/TransactionStatement.java:
##########
@@ -207,12 +204,9 @@ public ResultSet.ResultMetadata getResultMetadata()
TxnNamedRead createNamedRead(NamedSelect namedSelect, QueryOptions options, ClientState state)
{
SelectStatement select = namedSelect.select;
- ReadQuery readQuery = select.getQuery(options, 0);
- checkTrue(readQuery instanceof SinglePartitionReadQuery.Group, ILLEGAL_RANGE_QUERY_MESSAGE, select.asCQL(options, state));
-
// We reject reads from both LET and SELECT that do not specify a single row.
@SuppressWarnings("unchecked")
- SinglePartitionReadQuery.Group<SinglePartitionReadCommand> selectQuery = (SinglePartitionReadQuery.Group<SinglePartitionReadCommand>) readQuery;
+ SinglePartitionReadQuery.Group<SinglePartitionReadCommand> selectQuery = (SinglePartitionReadQuery.Group<SinglePartitionReadCommand>) select.getQuery(options, 0);
Review Comment:
In and the other case, the statement at this point is guaranteed to not be partition range query. It has been verified during preparation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] jacek-lewandowski commented on a diff in pull request #2195: [CASSANDRA-18302] Statement source descriptions
Posted by "jacek-lewandowski (via GitHub)" <gi...@apache.org>.
jacek-lewandowski commented on code in PR #2195:
URL: https://github.com/apache/cassandra/pull/2195#discussion_r1132071739
##########
src/java/org/apache/cassandra/cql3/statements/TransactionStatement.java:
##########
@@ -207,12 +204,9 @@ public ResultSet.ResultMetadata getResultMetadata()
TxnNamedRead createNamedRead(NamedSelect namedSelect, QueryOptions options, ClientState state)
{
SelectStatement select = namedSelect.select;
- ReadQuery readQuery = select.getQuery(options, 0);
- checkTrue(readQuery instanceof SinglePartitionReadQuery.Group, ILLEGAL_RANGE_QUERY_MESSAGE, select.asCQL(options, state));
-
// We reject reads from both LET and SELECT that do not specify a single row.
@SuppressWarnings("unchecked")
- SinglePartitionReadQuery.Group<SinglePartitionReadCommand> selectQuery = (SinglePartitionReadQuery.Group<SinglePartitionReadCommand>) readQuery;
+ SinglePartitionReadQuery.Group<SinglePartitionReadCommand> selectQuery = (SinglePartitionReadQuery.Group<SinglePartitionReadCommand>) select.getQuery(options, 0);
Review Comment:
In this and the other case, the statement at this point is guaranteed to not be partition range query. It has been verified during preparation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] jacek-lewandowski commented on a diff in pull request #2195: [CASSANDRA-18302] Statement source descriptions
Posted by "jacek-lewandowski (via GitHub)" <gi...@apache.org>.
jacek-lewandowski commented on code in PR #2195:
URL: https://github.com/apache/cassandra/pull/2195#discussion_r1132070531
##########
src/java/org/apache/cassandra/cql3/StatementSource.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.cassandra.cql3;
+
+import java.util.Objects;
+import java.util.regex.Pattern;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import com.google.common.base.Preconditions;
+
+import org.antlr.runtime.Token;
+import org.apache.cassandra.cql3.statements.QualifiedStatement;
+
+public class StatementSource
+{
+ public static final StatementSource INTERNAL = Bounds.INTERNAL.describeSource(null);
+
+ public final String text;
+ public final Bounds bounds;
+
+ public StatementSource(@Nullable String text, @Nonnull Bounds bounds)
+ {
+ Objects.requireNonNull(bounds);
+ this.text = text;
+ this.bounds = bounds;
+ }
+
+ public String describe(boolean mayIncludeSourceText)
+ {
+ if (this == INTERNAL)
+ {
+ return "<<<internal statement>>>";
+ }
+ else
+ {
+ if (bounds != Bounds.INTERNAL && !bounds.isEmpty() && text != null && mayIncludeSourceText)
+ return String.format("at %d:%d - %s", bounds.startLine + 1, bounds.startChar + 1, text);
+ else if (bounds != Bounds.INTERNAL && !bounds.isEmpty())
+ return String.format("at %d:%d", bounds.startLine + 1, bounds.startChar + 1);
+ else if (text != null && !bounds.isEmpty() && mayIncludeSourceText)
+ return String.format("%s", text);
+ else
+ return "";
+ }
+ }
+
+ public static Bounds createBounds(Token startToken, Token endToken)
+ {
+ Objects.requireNonNull(startToken);
+ Objects.requireNonNull(endToken);
+
+ int startLine, startChar, endLine, endChar;
+
+ if (startToken.getType() == Token.EOF)
+ {
+ startLine = Character.MAX_VALUE;
+ startChar = Character.MAX_VALUE;
+ }
+ else
+ {
+ startLine = Math.min(Math.max(startToken.getLine(), 1) - 1, Character.MAX_VALUE);
+ startChar = Math.min(Math.max(startToken.getCharPositionInLine(), 0), Character.MAX_VALUE);
+ }
+
+ if (endToken.getType() == Token.EOF)
+ {
+ endLine = Character.MAX_VALUE;
+ endChar = Character.MAX_VALUE;
+ }
+ else
+ {
+ endLine = Math.min(Math.max(endToken.getLine(), 1) - 1, Character.MAX_VALUE);
+ endChar = Math.min(Math.max(endToken.getCharPositionInLine(), 0), Character.MAX_VALUE);
+ }
+
+ return new Bounds(startLine, startChar, endLine, endChar);
+ }
+
+ public static class Bounds
+ {
+ public static final Bounds INTERNAL = new Bounds(0, 0, Character.MAX_VALUE, Character.MAX_VALUE);
+
+ private static final Pattern LINE_BREAK = Pattern.compile("\\R");
+ private static final String SEPARATOR = " ";
+
+ private final int startLine;
+ private final int startChar;
+ private final int endLine;
+ private final int endChar;
+
+ private Bounds(int startLine, int startChar, int endLine, int endChar)
+ {
+ Preconditions.checkArgument(startLine >= 0 && startLine <= Character.MAX_VALUE);
+ Preconditions.checkArgument(startChar >= 0 && startChar <= Character.MAX_VALUE);
+ Preconditions.checkArgument(endLine >= 0 && endLine <= Character.MAX_VALUE);
+ Preconditions.checkArgument(endChar >= 0 && endChar <= Character.MAX_VALUE);
+
+ this.startLine = startLine;
+ this.startChar = startChar;
+ this.endLine = endLine;
+ this.endChar = endChar;
+ }
+
+ private boolean isEmpty()
+ {
+ return startLine == Character.MAX_VALUE ||
+ startLine > endLine ||
Review Comment:
In all those pointed out cases I tried to make this class super resistant to wrong input regardless of the circumstances. But it can fail as well.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] maedhroz commented on a diff in pull request #2195: [CASSANDRA-18302] Statement source descriptions
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #2195:
URL: https://github.com/apache/cassandra/pull/2195#discussion_r1134651853
##########
src/java/org/apache/cassandra/cql3/statements/BatchStatement.java:
##########
@@ -235,7 +261,7 @@ public void validate() throws InvalidRequestException
for (ModificationStatement stmt : statements)
{
if (ksName != null && (!stmt.keyspace().equals(ksName) || !stmt.table().equals(cfName)))
- throw new InvalidRequestException("Batch with conditions cannot span multiple tables");
+ throw new InvalidRequestException("Batch with conditions cannot span multiple tables: " + stmt.source.describe(true));
Review Comment:
Is there any coverage for these two cases in `BatchTest`? In general, feels like it would be good to have a test for the `ModificationStatement` case...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] jacek-lewandowski commented on a diff in pull request #2195: [CASSANDRA-18302] Statement source descriptions
Posted by "jacek-lewandowski (via GitHub)" <gi...@apache.org>.
jacek-lewandowski commented on code in PR #2195:
URL: https://github.com/apache/cassandra/pull/2195#discussion_r1132075201
##########
src/java/org/apache/cassandra/cql3/statements/DeleteStatement.java:
##########
@@ -174,7 +186,8 @@ protected ModificationStatement prepareInternal(ClientState state,
operations,
restrictions,
conditions,
- attrs);
+ attrs,
+ bounds.describeSource(enclosingStatement));
Review Comment:
No, notice that the enclosing composite statement is a parsed statement and it already exists so as the parsed delete statement.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] jacek-lewandowski merged pull request #2195: [CASSANDRA-18302] Statement source descriptions
Posted by "jacek-lewandowski (via GitHub)" <gi...@apache.org>.
jacek-lewandowski merged PR #2195:
URL: https://github.com/apache/cassandra/pull/2195
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org