korlov42 commented on code in PR #3307:
URL: https://github.com/apache/ignite-3/pull/3307#discussion_r1511076149
##########
modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientSchema.java:
##########
@@ -63,34 +66,64 @@ public class ClientSchema {
*
* @param ver Schema version.
* @param columns Columns.
- * @param colocationColumns Colocation columns. When null, all key columns
are used.
* @param marshallers Marshallers provider.
*/
- public ClientSchema(int ver, ClientColumn[] columns, ClientColumn
@Nullable [] colocationColumns, MarshallersProvider marshallers) {
+ public ClientSchema(
+ int ver,
+ ClientColumn[] columns,
+ MarshallersProvider marshallers) {
assert ver >= 0;
assert columns != null;
this.ver = ver;
this.columns = columns;
this.marshallers = marshallers;
- var keyCnt = 0;
+
+ int keyColumnCount = 0;
+ int colocationColumnCount = 0;
for (var col : columns) {
+ ClientColumn existing = map.put(col.name(), col);
+ assert existing == null : "Duplicate column name: " + col.name();
+
if (col.key()) {
- keyCnt++;
+ keyColumnCount++;
}
- map.put(col.name(), col);
+ if (col.colocationIndex() >= 0) {
+ colocationColumnCount++;
+ }
}
- keyColumnCount = keyCnt;
+ int valColumnCount = columns.length - keyColumnCount;
+
+ this.keyColumns = keyColumnCount == 0 ? EMPTY_COLUMNS : new
ClientColumn[keyColumnCount];
+ this.colocationColumns = colocationColumnCount == 0 ? keyColumns : new
ClientColumn[colocationColumnCount];
+ this.valColumns = valColumnCount == 0 ? EMPTY_COLUMNS : new
ClientColumn[valColumnCount];
+
+ for (var col : columns) {
+ if (col.key()) {
+ assert this.keyColumns[col.keyIndex()] == null : "Duplicate
key index: name=" + col.name() + ", keyIndex=" + col.keyIndex()
+ + ", other.name=" +
this.keyColumns[col.keyIndex()].name();
+
+ assert col.keyIndex() == 0 || this.keyColumns[col.keyIndex() -
1] != null : "Key index is out of order: name="
Review Comment:
This assertion doesn't look valid. The order of key columns may not match
the order of columns in the table declaration, and this is perfectly valid
schema. I would say, the proper assertion here is that after we processed all
the columns, neither of `keyColumns` and `valColumns` contains `null`'s
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]