@@ -17,6 +17,7 @@ public class BasicTable extends AbstractEntity implements Table{
17
17
private List <String > colNames = new ArrayList <String >();
18
18
private Map <String , Integer > colNamesIndex = new HashMap <String , Integer >();
19
19
private int [] colCompresses = null ;
20
+ private int colRows ;
20
21
21
22
public BasicTable (ExtendedDataInput in ) throws IOException {
22
23
int rows = in .readInt ();
@@ -60,6 +61,7 @@ public BasicTable(ExtendedDataInput in) throws IOException{
60
61
}
61
62
if (vector .rows () != rows && vector .rows ()!= 1 )
62
63
throw new IOException ("The number of rows for column " + colNames .get (i ) + " is not consistent with other columns" );
64
+ this .colRows = rows ;
63
65
columns .add (vector );
64
66
}
65
67
if (collection != null )
@@ -70,10 +72,11 @@ public BasicTable(final List<String> colNames, final List<Vector> cols) {
70
72
if (colNames .size () != cols .size ()){
71
73
throw new Error ("The length of column name and column data is unequal." );
72
74
}
73
- int rowsCount = cols .get (0 ).rows ();
75
+
76
+ this .colRows = cols .get (0 ).rows ();
74
77
for (int i =0 ;i <cols .size ();i ++) {
75
78
Vector v = cols .get (i );
76
- if (v .rows () != rowsCount )
79
+ if (v .rows () != this . colRows )
77
80
throw new Error ("The length of column " + colNames .get (i ) + " must be the same as the first column length." );
78
81
}
79
82
this .setColName (colNames );
@@ -165,7 +168,7 @@ public int rows() {
165
168
if (columns ()<=0 )
166
169
return 0 ;
167
170
else
168
- return columns . get ( 0 ). rows () ;
171
+ return this . colRows ;
169
172
}
170
173
171
174
@ Override
@@ -380,9 +383,14 @@ public void addColumn(String colName, Vector col) {
380
383
381
384
if (colNames .contains (colName ))
382
385
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
+
383
390
colNames .add (colName );
384
391
colNamesIndex .put (colName , colNamesIndex .size ());
385
392
columns .add (col );
393
+ this .colRows = col .rows ();
386
394
}
387
395
388
396
@ Override
0 commit comments