-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34ac335
commit da29efe
Showing
9 changed files
with
170 additions
and
13 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
std-bits/table/src/main/java/org/enso/table/data/column/storage/BoolStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
std-bits/table/src/main/java/org/enso/table/data/column/storage/DoubleStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
std-bits/table/src/main/java/org/enso/table/data/column/storage/LongStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
std-bits/table/src/main/java/org/enso/table/data/column/storage/NullStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package org.enso.table.data.column.storage; | ||
|
||
import org.enso.table.data.mask.OrderMask; | ||
|
||
import java.util.BitSet; | ||
|
||
public class NullStorage extends Storage { | ||
private final int size; | ||
|
||
public NullStorage(int size) { | ||
this.size = size; | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return this.size; | ||
} | ||
|
||
@Override | ||
public int countMissing() { | ||
return this.size; | ||
} | ||
|
||
@Override | ||
public long getType() { return Type.OBJECT; } | ||
|
||
@Override | ||
public boolean isNa(long idx) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Object getItemBoxed(int idx) { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected boolean isOpVectorized(String name) { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected Storage runVectorizedMap(String name, Object argument) { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected Storage runVectorizedZip(String name, Storage argument) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Storage mask(BitSet mask, int cardinality) { return new NullStorage(cardinality); } | ||
|
||
@Override | ||
public Storage applyMask(OrderMask mask) { return new NullStorage(mask.getPositions().length); } | ||
|
||
@Override | ||
public Storage countMask(int[] counts, int total) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Storage slice(int offset, int limit) { | ||
return new NullStorage(Math.min(size - offset, limit)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
std-bits/table/src/main/java/org/enso/table/data/column/storage/StringStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
std-bits/table/src/main/java/org/enso/table/util/ColumnMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.enso.table.util; | ||
|
||
import org.enso.table.data.column.storage.NullStorage; | ||
import org.enso.table.data.table.Column; | ||
import org.enso.table.data.table.Table; | ||
import org.enso.table.problems.Problem; | ||
import org.enso.table.problems.WithProblems; | ||
import org.enso.table.util.problems.ColumnCountMismatch; | ||
import org.enso.table.util.problems.ColumnNameMismatch; | ||
|
||
import java.util.*; | ||
|
||
public class ColumnMapper { | ||
public static WithProblems<Table> MapColumnsByName(Table table, String[] columnNames) { | ||
Column[] columns = new Column[columnNames.length]; | ||
Set<String> extras = new HashSet<>(Arrays.asList(columnNames)); | ||
Set<String> missing = new HashSet<>(); | ||
|
||
for (int i = 0; i < columnNames.length; i++) { | ||
String name = columnNames[i]; | ||
Column column = table.getColumnByName(name); | ||
if (column == null) { | ||
missing.add(name); | ||
NullStorage storage = new NullStorage(columns[0].getStorage().size()); | ||
columns[i] = new Column(java.util.UUID.randomUUID().toString(), storage); | ||
} else { | ||
extras.remove(name); | ||
columns[i] = column; | ||
} | ||
} | ||
|
||
Table newTable = new Table(columns); | ||
if (missing.isEmpty() && extras.isEmpty()) { | ||
return new WithProblems<>(newTable, Collections.emptyList()); | ||
} else { | ||
Problem problem = new ColumnNameMismatch(missing.toArray(String[]::new), extras.toArray(String[]::new)); | ||
return new WithProblems<>(newTable, List.of(problem)); | ||
} | ||
} | ||
|
||
public static WithProblems<Table> MapColumnsByIndex(Table table, int columnCount) { | ||
Column[] columns = table.getColumns(); | ||
if (columns.length == columnCount) { | ||
return new WithProblems<>(table, Collections.emptyList()); | ||
} | ||
|
||
Column[] newColumns = new Column[columnCount]; | ||
System.arraycopy(columns, 0, newColumns, 0, Math.min(columnCount, columns.length)); | ||
if (columns.length < columnCount) { | ||
NullStorage storage = new NullStorage(columns[0].getStorage().size()); | ||
Arrays.fill(newColumns, columns.length, columnCount, new Column(java.util.UUID.randomUUID().toString(), storage)); | ||
} | ||
|
||
Problem problem = new ColumnCountMismatch(columnCount, columns.length); | ||
return new WithProblems<>(new Table(newColumns), List.of(problem)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters