AMashenkov commented on code in PR #2203:
URL: https://github.com/apache/ignite-3/pull/2203#discussion_r1519390206
##########
modules/schema/src/main/java/org/apache/ignite/internal/schema/SchemaDescriptor.java:
##########
@@ -84,71 +82,118 @@ public class SchemaDescriptor {
* @param keyCols Key columns.
* @param valCols Value columns.
*/
+ @TestOnly
public SchemaDescriptor(int ver, Column[] keyCols, Column[] valCols) {
- this(ver, keyCols, null, valCols);
+ this(
+ ver,
+ mergeColumns(keyCols, valCols),
+
Arrays.stream(keyCols).map(Column::name).collect(Collectors.toList()),
+ null
+ );
}
- /**
- * Constructor.
- *
- * @param ver Schema version.
- * @param keyCols Key columns.
- * @param colocationCols Colocation column names.
- * @param valCols Value columns.
- */
- public SchemaDescriptor(int ver, Column[] keyCols, String @Nullable[]
colocationCols, Column[] valCols) {
- assert keyCols.length > 0 : "No key columns are configured.";
+ /** Constructor. */
+ public SchemaDescriptor(
+ int ver,
+ List<Column> columns,
+ List<String> keyColumns,
+ @Nullable List<String> colocationColumns
+ ) {
+ assert !nullOrEmpty(columns) : "Schema should have at least one
column";
+
+ Map<String, Column> columnsByName = new HashMap<>();
+ List<Column> orderedColumns = new ArrayList<>(columns.size());
+
+ Object2IntMap<String> columnNameToPositionInKey = new
Object2IntOpenHashMap<>();
+ int idx = 0;
+ for (String name : keyColumns) {
+ assert !columnNameToPositionInKey.containsKey(name)
+ : "Key column must not have duplicates: " + name;
+
+ columnNameToPositionInKey.put(name, idx++);
+ }
Review Comment:
This can be an utility method.
Validation can be placed into a separate ` if (isAssertionEnabled)` block,
or even throw an exception.
--
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]