/** * Parse condition for column. * * @param colIdx Column index. * @param start Start row values. * @param end End row values. */ public static SqlSystemViewColumnCondition forColumn(int colIdx, SearchRow start, SearchRow end) { boolean isEquality = false; boolean isRange = false; Value val = null; Value val2 = null; if (start != null && colIdx >= 0 && colIdx < start.getColumnCount()) val = start.getValue(colIdx); if (end != null && colIdx >= 0 && colIdx < end.getColumnCount()) val2 = end.getValue(colIdx); if (val != null && val2 != null) { if (val.equals(val2)) isEquality = true; else isRange = true; } else if (val != null || val2 != null) isRange = true; return new SqlSystemViewColumnCondition(isEquality, isRange, val); }
/** * Get the size of a row (only the part that is stored in the index). * * @param dummy a dummy data page to calculate the size * @param row the row * @param onlyPosition whether only the position of the row is stored * @return the number of bytes */ int getRowSize(Data dummy, SearchRow row, boolean onlyPosition) { int rowsize = Data.getVarLongLen(row.getKey()); if (!onlyPosition) { for (Column col : columns) { Value v = row.getValue(col.getColumnId()); rowsize += dummy.getValueLen(v); } } return rowsize; }
@Override public void setKeyAndVersion(SearchRow row) { key = row.getKey(); version = row.getVersion(); }
/** * @param row Row. * @return ID. */ private static ValueInt id(SearchRow row) { Value id = row.getValue(ID); assert id != null; return (ValueInt)id; }
/** * Convert array of values to a SearchRow. * * @param key the index key * @return the row */ SearchRow convertToSearchRow(ValueArray key) { Value[] array = key.getList(); SearchRow searchRow = mvTable.getTemplateRow(); searchRow.setKey((array[array.length - 1]).getLong()); Column[] cols = getColumns(); for (int i = 0; i < array.length - 1; i++) { Column c = cols[i]; int idx = c.getColumnId(); Value v = array[i]; searchRow.setValue(idx, v); } return searchRow; }
/** * Create a search row for this row. * * @param row the row * @return the search row */ private SearchRow getSearchRow(Row row) { SearchRow r = table.getTemplateSimpleRow(columns.length == 1); r.setKeyAndVersion(row); for (Column c : columns) { int idx = c.getColumnId(); r.setValue(idx, row.getValue(idx)); } return r; }
public int compareKeys(SearchRow rowData, SearchRow compare) { int k1 = rowData.getPos(); int k2 = compare.getPos(); if (k1 == k2) { if (isMultiVersion) { int v1 = rowData.getVersion(); int v2 = compare.getVersion(); return v1 == v2 ? 0 : v1 < v2 ? 1 : -1; } return 0; } return k1 > k2 ? 1 : -1; }
/** {@inheritDoc} */ @Override public int getColumnCount() { return row.getColumnCount(); }
/** * Get the row with the given index key. * * @param key the index key * @return the row */ SearchRow getRow(SpatialKey key) { SearchRow searchRow = mvTable.getTemplateRow(); searchRow.setKey(key.getId()); return searchRow; }
@Override protected void memoryChange() { if (!PageBtreeIndex.isMemoryChangeRequired()) { return; } int memory = Constants.MEMORY_PAGE_BTREE + index.getPageStore().getPageSize(); if (rows != null) { memory += getEntryCount() * (4 + Constants.MEMORY_POINTER); for (int i = 0; i < entryCount; i++) { SearchRow r = rows[i]; if (r != null) { memory += r.getMemory(); } } } index.memoryChange(memory >> 2); }
SearchRow getSearchRow(Row row) { SearchRow r = table.getTemplateSimpleRow(columns.length == 1); r.setPosAndVersion(row); for (int j = 0; j < columns.length; j++) { int idx = columns[j].getColumnId(); r.setValue(idx, row.getValue(idx)); } return r; }
/** {@inheritDoc} */ @Override public int getVersion() { return row.getVersion(); }
/** {@inheritDoc} */ @Override public void setKeyAndVersion(SearchRow old) { row.setKeyAndVersion(old); }
private SearchRow getSpatialSearchRow(SearchRow row, int columnId, Value v) { if (row == null) { row = table.getTemplateRow(); } else if (row.getValue(columnId) != null) { // if an object needs to overlap with both a and b, // then it needs to overlap with the the union of a and b // (not the intersection) ValueGeometry vg = (ValueGeometry) row.getValue(columnId). convertTo(Value.GEOMETRY); v = ((ValueGeometry) v.convertTo(Value.GEOMETRY)). getEnvelopeUnion(vg); } if (columnId < 0) { row.setKey(v.getLong()); } else { row.setValue(columnId, v); } return row; }
@Override public int compareRows(SearchRow rowData, SearchRow compare) { if (rowData == compare) { return 0; } for (int i = 0, len = indexColumns.length; i < len; i++) { int index = columnIds[i]; Value v1 = rowData.getValue(index); Value v2 = compare.getValue(index); if (v1 == null || v2 == null) { // can't compare further return 0; } int c = compareValues(v1, v2, indexColumns[i].sortType); if (c != 0) { return c; } } return 0; }