private ValueResultSet getTable( Session session, Expression[] argList, boolean onlyColumnList, boolean distinctRows) { int len = columnList.length; Expression[] header = new Expression[len]; Database db = session.getDatabase(); for (int i = 0; i < len; i++) { Column c = columnList[i]; ExpressionColumn col = new ExpressionColumn(db, c); header[i] = col; } LocalResult result = new LocalResult(session, header, len); if (distinctRows) { result.setDistinct(); } if (!onlyColumnList) { Value[][] list = new Value[len][]; int rows = 0; for (int i = 0; i < len; i++) { Value v = argList[i].getValue(session); if (v == ValueNull.INSTANCE) { list[i] = new Value[0]; } else { ValueArray array = (ValueArray) v.convertTo(Value.ARRAY); Value[] l = array.getList(); list[i] = l; rows = Math.max(rows, l.length); } } for (int row = 0; row < rows; row++) { Value[] r = new Value[len]; for (int j = 0; j < len; j++) { Value[] l = list[j]; Value v; if (l.length <= row) { v = ValueNull.INSTANCE; } else { Column c = columnList[j]; v = l[row]; v = c.convert(v); v = v.convertPrecision(c.getPrecision(), false); v = v.convertScale(true, c.getScale()); } r[j] = v; } result.addRow(r); } } result.done(); ValueResultSet vr = ValueResultSet.get(getSimpleResultSet(result, Integer.MAX_VALUE)); return vr; }
@Override public Row get() { if (row == null) { if (searchRow != null) { Result r; try { Get get = new Get(HBaseUtils.toBytes(searchRow.getRowKey())); get.setTimeStamp(searchTimestamp); if (columns != null) { for (Column c : columns) { if (c.isRowKeyColumn()) continue; else if (c.getColumnFamilyName() != null) get.addColumn(c.getColumnFamilyNameAsBytes(), c.getNameAsBytes()); else get.addColumn(defaultColumnFamilyName, c.getNameAsBytes()); } } r = secondaryIndex.dataTable.get(get); } catch (IOException e) { throw DbException.convert(e); } if (r != null) { Value[] data = new Value[columns.size()]; Value rowKey = ValueString.get(Bytes.toString(r.getRow())); if (columns != null) { int i = 0; for (Column c : columns) { i = c.getColumnId(); if (c.isRowKeyColumn()) data[i] = rowKey; else data[i] = HBaseUtils.toValue( // r.getValue(c.getColumnFamilyNameAsBytes(), c.getNameAsBytes()), c.getType()); } } row = new HBaseRow(null, rowKey, data, Row.MEMORY_CALCULATE, r); } } } return row; }