Skip to content

Commit 2aa2dab

Browse files
author
chengyitian
committed
AJ-456、AJ-457: throw exception when new column's rows doesn't match exits cols' size; add new property colRows.
1 parent fa1fbc5 commit 2aa2dab

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/com/xxdb/data/BasicTable.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class BasicTable extends AbstractEntity implements Table{
1717
private List<String> colNames = new ArrayList<String>();
1818
private Map<String, Integer> colNamesIndex = new HashMap<String, Integer>();
1919
private int[] colCompresses = null;
20+
private int colRows;
2021

2122
public BasicTable(ExtendedDataInput in) throws IOException{
2223
int rows = in.readInt();
@@ -60,6 +61,7 @@ public BasicTable(ExtendedDataInput in) throws IOException{
6061
}
6162
if(vector.rows() != rows && vector.rows()!= 1)
6263
throw new IOException("The number of rows for column " + colNames.get(i) + " is not consistent with other columns");
64+
this.colRows = rows;
6365
columns.add(vector);
6466
}
6567
if(collection != null)
@@ -70,10 +72,11 @@ public BasicTable(final List<String> colNames, final List<Vector> cols) {
7072
if(colNames.size() != cols.size()){
7173
throw new Error("The length of column name and column data is unequal.");
7274
}
73-
int rowsCount = cols.get(0).rows();
75+
76+
this.colRows = cols.get(0).rows();
7477
for (int i=0;i<cols.size();i++) {
7578
Vector v = cols.get(i);
76-
if(v.rows() != rowsCount)
79+
if(v.rows() != this.colRows)
7780
throw new Error("The length of column " + colNames.get(i) + " must be the same as the first column length.");
7881
}
7982
this.setColName(colNames);
@@ -165,7 +168,7 @@ public int rows() {
165168
if(columns()<=0)
166169
return 0;
167170
else
168-
return columns.get(0).rows();
171+
return this.colRows;
169172
}
170173

171174
@Override
@@ -380,9 +383,14 @@ public void addColumn(String colName, Vector col) {
380383

381384
if (colNames.contains(colName))
382385
throw new RuntimeException("The table already contains column '" + colName + "'.");
386+
387+
if (this.colRows != 0 && col.rows() != this.colRows)
388+
throw new RuntimeException("The length of column " + colName + " must be the same as the first column length: " + this.colRows +".");
389+
383390
colNames.add(colName);
384391
colNamesIndex.put(colName, colNamesIndex.size());
385392
columns.add(col);
393+
this.colRows = col.rows();
386394
}
387395

388396
@Override

src/com/xxdb/streaming/client/MessageParser.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,8 @@ public void run() {
6262

6363
if (this.dBConnectionAndSocket == null ) {
6464
throw new Exception("dBConnectionAndSocket is null!");
65-
} else
66-
{
67-
if (this.dBConnectionAndSocket.socket != null)
68-
{
65+
} else {
66+
if (this.dBConnectionAndSocket.socket != null) {
6967
if (this.dBConnectionAndSocket.conn != null)
7068
throw new Exception("Either conn or socket must be null!");
7169
socket = this.dBConnectionAndSocket.socket;

0 commit comments

Comments
 (0)