Skip to content

Commit

Permalink
PHOENIX-7185 Error message in SequenceNotFoundException is misleading
Browse files Browse the repository at this point in the history
  • Loading branch information
Anchal Kejriwal committed Mar 8, 2024
1 parent 0ceccde commit 62a1cd9
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,13 @@ public SQLException newException(SQLExceptionInfo info) {
SEQUENCE_ALREADY_EXIST(1200, "42Z00", "Sequence already exists.", new Factory() {
@Override
public SQLException newException(SQLExceptionInfo info) {
return new SequenceAlreadyExistsException(info.getSchemaName(), info.getTableName());
return new SequenceAlreadyExistsException(info.getSchemaName(), info.getSequenceName());
}
}),
SEQUENCE_UNDEFINED(1201, "42Z01", "Sequence undefined.", new Factory() {
@Override
public SQLException newException(SQLExceptionInfo info) {
return new SequenceNotFoundException(info.getSchemaName(), info.getTableName());
return new SequenceNotFoundException(info.getSchemaName(), info.getSequenceName());
}
}),
START_WITH_MUST_BE_CONSTANT(1202, "42Z02", "Sequence START WITH value must be an integer or long constant."),
Expand All @@ -392,7 +392,7 @@ public SQLException newException(SQLExceptionInfo info) {
AUTO_PARTITION_SEQUENCE_UNDEFINED(1217, "42Z17", "Auto Partition Sequence undefined", new Factory() {
@Override
public SQLException newException(SQLExceptionInfo info) {
return new SequenceNotFoundException(info.getSchemaName(), info.getTableName());
return new SequenceNotFoundException(info.getSchemaName(), info.getSequenceName());
}
}),
CANNOT_UPDATE_PK_ON_DUP_KEY(1218, "42Z18", "Primary key columns may not be udpated in ON DUPLICATE KEY UPDATE clause." ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class SQLExceptionInfo {
public static final String MAX_PHOENIX_COLUMN_SIZE_BYTES = "maxPhoenixColumnSizeBytes";
public static final String PHOENIX_COLUMN_SIZE_BYTES = "phoenixColumnSizeBytes";
public static final String HA_GROUP_INFO = "haGroupInfo";
public static final String SEQUENCE_NAME = "sequenceName";

private final Throwable rootCause;
private final SQLExceptionCode code; // Should always have one.
Expand All @@ -61,6 +62,7 @@ public class SQLExceptionInfo {
private final int phoenixColumnSizeBytes;
private final int maxPhoenixColumnSizeBytes;
private final String haGroupInfo;
private final String sequenceName;

public static class Builder {
private Throwable rootCause;
Expand All @@ -78,6 +80,7 @@ public static class Builder {
private int phoenixColumnSizeBytes;
private int maxPhoenixColumnSizeBytes;
private String haGroupInfo;
private String sequenceName;

public Builder(SQLExceptionCode code) {
this.code = code;
Expand Down Expand Up @@ -161,6 +164,11 @@ public SQLExceptionInfo build() {
public String toString() {
return code.toString();
}

public Builder setSequenceName(String sequenceName) {
this.sequenceName = sequenceName;
return this;
}
}

private SQLExceptionInfo(Builder builder) {
Expand All @@ -179,6 +187,7 @@ private SQLExceptionInfo(Builder builder) {
maxPhoenixColumnSizeBytes = builder.maxPhoenixColumnSizeBytes;
phoenixColumnSizeBytes = builder.phoenixColumnSizeBytes;
haGroupInfo = builder.haGroupInfo;
sequenceName = builder.sequenceName;
}

@Override
Expand All @@ -192,6 +201,10 @@ public String toString() {
builder.append(" ").append(message);
}
}
if (sequenceName != null) {
builder.append(" ").append(SEQUENCE_NAME).append("=").append(sequenceName);
return builder.toString();
}
if (functionName != null) {
builder.append(" ").append(FUNCTION_NAME).append("=").append(functionName);
return builder.toString();
Expand Down Expand Up @@ -288,4 +301,7 @@ public int getPhoenixColumnSizeBytes() {
public String getHaGroupInfo() {
return haGroupInfo;
}
public String getSequenceName() {
return sequenceName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3415,7 +3415,7 @@ public boolean handleCreateTableMutationCode(MetaDataMutationResult result, Muta
throw new ConcurrentTableMutationException(schemaName, tableName);
case AUTO_PARTITION_SEQUENCE_NOT_FOUND:
throw new SQLExceptionInfo.Builder(SQLExceptionCode.AUTO_PARTITION_SEQUENCE_UNDEFINED)
.setSchemaName(schemaName).setTableName(tableName).build().buildException();
.setSchemaName(schemaName).setSequenceName(tableName).build().buildException();
case CANNOT_COERCE_AUTO_PARTITION_ID:
case UNABLE_TO_CREATE_CHILD_LINK:
case PARENT_TABLE_NOT_FOUND:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public long incrementValue(Result result, ValueOp op, long numToAllocate) throws
// }
throw new SQLExceptionInfo.Builder(code)
.setSchemaName(key.getSchemaName())
.setTableName(key.getSequenceName())
.setSequenceName(key.getSequenceName())
.build().buildException();
}
// If we found the sequence, we update our cache with the new value
Expand Down Expand Up @@ -553,7 +553,7 @@ public boolean returnValue(Result result) throws SQLException {
// }
throw new SQLExceptionInfo.Builder(code)
.setSchemaName(key.getSchemaName())
.setTableName(key.getSequenceName())
.setSequenceName(key.getSequenceName())
.build().buildException();
}

Expand Down Expand Up @@ -626,7 +626,7 @@ public long dropSequence(Result result) throws SQLException {
// }
throw new SQLExceptionInfo.Builder(code)
.setSchemaName(key.getSchemaName())
.setTableName(key.getSequenceName())
.setSequenceName(key.getSequenceName())
.build().buildException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.exception.SQLExceptionInfo;


public class SequenceNotFoundException extends MetaDataEntityNotFoundException {
private static final long serialVersionUID = 1L;
private static SQLExceptionCode code = SQLExceptionCode.SEQUENCE_UNDEFINED;

public SequenceNotFoundException(String tableName) {
this(null, tableName);
public SequenceNotFoundException(String sequenceName) {
this(null, sequenceName);
}

public SequenceNotFoundException(String schemaName, String tableName) {
super(new SQLExceptionInfo.Builder(code).setSchemaName(schemaName).setTableName(tableName).build().toString(),
code.getSQLState(), code.getErrorCode(), schemaName, tableName, null);
public SequenceNotFoundException(String schemaName, String sequenceName) {
super(new SQLExceptionInfo.Builder(code).setSchemaName(schemaName).setSequenceName(sequenceName).build().toString(),
code.getSQLState(), code.getErrorCode(), schemaName, sequenceName, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public static boolean isCycleAllowed(long numToAllocate) {
/**
* Helper function that returns a {@link SQLException}
*/
public static SQLException getException(String schemaName, String tableName,
public static SQLException getException(String schemaName, String sequenceName,
SQLExceptionCode code) {
return new SQLExceptionInfo.Builder(code).setSchemaName(schemaName).setTableName(tableName)
return new SQLExceptionInfo.Builder(code).setSchemaName(schemaName).setSequenceName(sequenceName)
.build().buildException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.apache.phoenix.thirdparty.com.google.common.collect.Lists;
import org.apache.phoenix.schema.SequenceNotFoundException;


@Category(ParallelStatsDisabledTest.class)
Expand Down

0 comments on commit 62a1cd9

Please sign in to comment.