public byte[] getSerializedFilter() { if (this.condition != null) { ByteBuffer bbuf = ((ConditionImpl)this.condition).getDescriptor().getSerialized(); byte[] serFilter = new byte[bbuf.limit() - bbuf.position()]; bbuf.get(serFilter); return serFilter; } return null; }
@JsonCreator public JsonScanSpec(@JsonProperty("tableName") String tableName, @JsonProperty("indexDesc") IndexDesc indexDesc, @JsonProperty("condition") QueryCondition condition) { this.tableName = tableName; this.indexDesc = indexDesc; this.condition = condition; if (this.condition != null) { List<RowkeyRange> rkRanges = ((ConditionImpl)this.condition).getRowkeyRanges(); if (rkRanges.size() > 0) { startRow = rkRanges.get(0).getStartRow(); stopRow = rkRanges.get(rkRanges.size() - 1).getStopRow(); } else { startRow = HConstants.EMPTY_START_ROW; stopRow = HConstants.EMPTY_END_ROW; } } }
@Override public int compareTo(TabletFragmentInfo o) { return tabletInfoImpl != null ? tabletInfoImpl.compareTo(o.tabletInfoImpl) : regionInfo.compareTo(o.regionInfo); }
switch (functionName) { case "equal": cond = MapRDBImpl.newCondition(); setIsCondition(cond, fieldPath, Op.EQUAL, fieldValue); break; cond = MapRDBImpl.newCondition(); setIsCondition(cond, fieldPath, Op.NOT_EQUAL, fieldValue); break; cond = MapRDBImpl.newCondition(); setIsCondition(cond, fieldPath, Op.LESS, fieldValue); break; cond = MapRDBImpl.newCondition(); setIsCondition(cond, fieldPath, Op.LESS_OR_EQUAL, fieldValue); break; cond = MapRDBImpl.newCondition(); setIsCondition(cond, fieldPath, Op.GREATER, fieldValue); break; cond = MapRDBImpl.newCondition(); setIsCondition(cond, fieldPath, Op.GREATER_OR_EQUAL, fieldValue); break; cond = MapRDBImpl.newCondition().notExists(fieldPath); break;
protected MapRDBSubScanSpec getSubScanSpec(final TabletFragmentInfo tfi) { // XXX/TODO check filter/Condition final JsonScanSpec spec = scanSpec; final String serverHostName = getRegionsToScan().get(tfi); QueryCondition condition = tfi.getTabletInfoImpl().getCondition(); byte[] startRow = condition == null ? null : ((ConditionImpl) condition).getRowkeyRanges().get(0).getStartRow(); byte[] stopRow = condition == null ? null : ((ConditionImpl) condition).getRowkeyRanges().get(0).getStopRow(); JsonSubScanSpec subScanSpec = new JsonSubScanSpec( spec.getTableName(), spec.getIndexDesc(), serverHostName, tfi.getTabletInfoImpl().getCondition(), spec.getCondition(), startRow, stopRow, getUserName()); return subScanSpec; }
@Override public Table load(final MapRDBTableCache.Key key) throws Exception { // getTable is already calling tableCache.get in correct user UGI context, so should be fine here. // key.Left is Path. key.Right is indexDesc. Table table = (key.indexDesc == null ? MapRDBImpl.getTable(key.path) : MapRDBImpl.getIndexTable(key.indexDesc)); logger.debug("time {} opened the table for tablePath {} tableHandle {} index {} userName {}", System.nanoTime(), key.path == null ? "null" : key.path, table == null ? "null" : table, key.indexDesc == null ? "null" : key.indexDesc.getIndexName(), key.ugi.getUserName() == null ? "null" : key.ugi.getUserName()); return table; } });
Table createOrGetTable(String tableName, int recordNum) { if (admin.tableExists(tableName)) { return MapRDBImpl.getTable(tableName); // admin.deleteTable(tableName); } else { TableDescriptor desc = new TableDescriptorImpl(new Path(tableName)); int splits = (recordNum / SPLIT_SIZE) - (((recordNum % SPLIT_SIZE) > 1)? 0 : 1); String[] splitsStr = new String[splits]; StringBuilder strBuilder = new StringBuilder("Splits:"); for (int i = 0; i < splits; ++i) { splitsStr[i] = String.format("%d", (i+1)*SPLIT_SIZE); strBuilder.append(splitsStr[i] + ", "); } System.out.print(strBuilder.toString()); return admin.createTable(desc, splitsStr); } }
public JsonSubScanSpec(String tableName, IndexDesc indexDesc, String regionServer, QueryCondition scanRangeCondition, QueryCondition userCondition, byte[] startRow, byte[] stopRow, String userName) { super(tableName, indexDesc, regionServer, startRow, stopRow, null, null, userName); condition = MapRDBImpl.newCondition().and(); if (userCondition != null && !userCondition.isEmpty()) { condition.condition(userCondition); } if (scanRangeCondition != null && !scanRangeCondition.isEmpty()) { condition.condition(scanRangeCondition); } condition.close().build(); }
@Override public String toString() { StringBuilder sb = new StringBuilder("MaprDBJsonRecordReader[Table=") .append(table != null ? table.getPath() : null); if (reader != null) { sb.append(", Document ID=") .append(IdCodec.asString(reader.getId())); } sb.append(", reader=") .append(reader) .append(']'); return sb.toString(); } }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((regionInfo == null) ? 0 : regionInfo.hashCode()); result = prime * result + ((tabletInfoImpl == null) ? 0 : tabletInfoImpl.hashCode()); return result; }
public byte[] getStartKey() { return tabletInfoImpl != null ? tabletInfoImpl.getStartRow() : regionInfo.getStartKey(); }
public boolean containsRow(byte[] row) { return tabletInfoImpl != null ? tabletInfoImpl.containsRow(row) : regionInfo.containsRow(row); }
public byte[] getEndKey() { return tabletInfoImpl != null ? tabletInfoImpl.getStopRow() : regionInfo.getEndKey(); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } TabletFragmentInfo other = (TabletFragmentInfo) obj; if (regionInfo == null) { if (other.regionInfo != null) { return false; } } else if (!regionInfo.equals(other.regionInfo)) { return false; } if (tabletInfoImpl == null) { if (other.tabletInfoImpl != null) { return false; } } else if (!tabletInfoImpl.equals(other.tabletInfoImpl)) { return false; } return true; }
/** * Returns ids of rowKeys to be read. * Number of rowKey ids returned will be numRowKeysToRead at the most i.e. it * will be less than numRowKeysToRead if only that many exist in the currentBatch. */ @JsonIgnore public ByteBuffer[] getRowKeyIdsToRead(int numRowKeysToRead) { int numKeys = hasRowKeys(numRowKeysToRead); if (numKeys == 0) { return null; } int index = 0; final ByteBuffer[] rowKeyIds = new ByteBuffer[numKeys]; while (index < numKeys) { Object o = rowKeyVector.getAccessor().getObject(currentIndex + index); rowKeyIds[index++] = IdCodec.encode(o.toString()); } updateRowKeysRead(numKeys); return rowKeyIds; }
public void mergeScanSpec(String functionName, JsonScanSpec scanSpec) { if (this.condition != null && scanSpec.getCondition() != null) { QueryCondition newCond = MapRDBImpl.newCondition(); switch (functionName) { case "booleanAnd": newCond.and(); break; case "booleanOr": newCond.or(); break; default: assert(false); } newCond.condition(this.condition) .condition(scanSpec.getCondition()) .close() .build(); this.condition = newCond; } else if (scanSpec.getCondition() != null){ this.condition = scanSpec.getCondition(); } }
private void createIndex(Table table, String[] indexDef) throws Exception { if (indexDef == null) { // don't create index here. indexes may have been created return; } for (int i = 0; i < indexDef.length / 3; ++i) { String indexCmd = String.format("maprcli table index add" + " -path " + table.getPath() + " -index %s" + " -indexedfields '%s'" + ((indexDef[3 * i + 2].length()==0)?"":" -includedfields '%s'") + ((indexDef[3 * i].startsWith("hash"))? " -hashed true" : ""), indexDefInCommand(indexDef[3 * i]), // index name indexDefInCommand(indexDef[3 * i + 1]), // indexedfields indexDefInCommand(indexDef[3 * i + 2])); // includedfields System.out.println(indexCmd); TestCluster.runCommand(indexCmd); DBTests.admin().getTableIndexes(table.getPath(), true); } }
public Table run() throws Exception { if (logger.isTraceEnabled()) { logger.trace("Getting MaprDB Table handle for proxy user: " + UserGroupInformation.getCurrentUser()); } if (tableCachingEnabled) { Table table = tableCache.get(new MapRDBTableCache.Key(tablePath, indexDesc)); logger.trace("time {} get the tablePath {} tableHandle {} index {} userName {} currentUser {}", System.nanoTime(), tablePath == null ? "null" : tablePath, table == null ? "null" : table, indexDesc == null ? "null" : indexDesc.getIndexName(), userName == null ? "null" : userName, UserGroupInformation.getCurrentUser() == null ? "null" : UserGroupInformation.getCurrentUser()); return table; } else { return indexDesc == null ? MapRDBImpl.getTable(tablePath) : MapRDBImpl.getIndexTable(indexDesc); } } });
@Override public byte[] getSerializedFilter() { if (this.condition != null) { ByteBuffer bbuf = ((ConditionImpl)this.condition).getDescriptor().getSerialized(); byte[] serFilter = new byte[bbuf.limit() - bbuf.position()]; bbuf.get(serFilter); return serFilter; } return null; } }
@Override public void writeDBDocument(VectorContainerWriter vectorWriter, DBDocumentReaderBase reader) throws SchemaChangeException { MapWriter writer = vectorWriter.rootAsMap(); Value id = reader.getId(); try { switch(id.getType()) { case STRING: valueWriter.writeString(writer, ID_KEY, id.getString()); break; case BINARY: valueWriter.writeBinary(writer, ID_KEY, id.getBinary()); break; default: throw new UnsupportedOperationException(id.getType() + " is not a supported type for _id field."); } } catch (IllegalStateException | IllegalArgumentException e) { throw schemaChangeException(logger, e, "Possible schema change at _id: '%s'", IdCodec.asString(id)); } }