1 // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
4 import java
.util
.Arrays
;
6 import java
.util
.Objects
;
9 * TableProperties contains read-only properties of its associated
12 public class TableProperties
{
13 private final long dataSize
;
14 private final long indexSize
;
15 private final long indexPartitions
;
16 private final long topLevelIndexSize
;
17 private final long indexKeyIsUserKey
;
18 private final long indexValueIsDeltaEncoded
;
19 private final long filterSize
;
20 private final long rawKeySize
;
21 private final long rawValueSize
;
22 private final long numDataBlocks
;
23 private final long numEntries
;
24 private final long numDeletions
;
25 private final long numMergeOperands
;
26 private final long numRangeDeletions
;
27 private final long formatVersion
;
28 private final long fixedKeyLen
;
29 private final long columnFamilyId
;
30 private final long creationTime
;
31 private final long oldestKeyTime
;
32 private final byte[] columnFamilyName
;
33 private final String filterPolicyName
;
34 private final String comparatorName
;
35 private final String mergeOperatorName
;
36 private final String prefixExtractorName
;
37 private final String propertyCollectorsNames
;
38 private final String compressionName
;
39 private final Map
<String
, String
> userCollectedProperties
;
40 private final Map
<String
, String
> readableProperties
;
41 private final Map
<String
, Long
> propertiesOffsets
;
44 * Access is package private as this will only be constructed from
45 * C++ via JNI and for testing.
47 TableProperties(final long dataSize
, final long indexSize
, final long indexPartitions
,
48 final long topLevelIndexSize
, final long indexKeyIsUserKey
,
49 final long indexValueIsDeltaEncoded
, final long filterSize
, final long rawKeySize
,
50 final long rawValueSize
, final long numDataBlocks
, final long numEntries
,
51 final long numDeletions
, final long numMergeOperands
, final long numRangeDeletions
,
52 final long formatVersion
, final long fixedKeyLen
, final long columnFamilyId
,
53 final long creationTime
, final long oldestKeyTime
, final byte[] columnFamilyName
,
54 final String filterPolicyName
, final String comparatorName
, final String mergeOperatorName
,
55 final String prefixExtractorName
, final String propertyCollectorsNames
,
56 final String compressionName
, final Map
<String
, String
> userCollectedProperties
,
57 final Map
<String
, String
> readableProperties
, final Map
<String
, Long
> propertiesOffsets
) {
58 this.dataSize
= dataSize
;
59 this.indexSize
= indexSize
;
60 this.indexPartitions
= indexPartitions
;
61 this.topLevelIndexSize
= topLevelIndexSize
;
62 this.indexKeyIsUserKey
= indexKeyIsUserKey
;
63 this.indexValueIsDeltaEncoded
= indexValueIsDeltaEncoded
;
64 this.filterSize
= filterSize
;
65 this.rawKeySize
= rawKeySize
;
66 this.rawValueSize
= rawValueSize
;
67 this.numDataBlocks
= numDataBlocks
;
68 this.numEntries
= numEntries
;
69 this.numDeletions
= numDeletions
;
70 this.numMergeOperands
= numMergeOperands
;
71 this.numRangeDeletions
= numRangeDeletions
;
72 this.formatVersion
= formatVersion
;
73 this.fixedKeyLen
= fixedKeyLen
;
74 this.columnFamilyId
= columnFamilyId
;
75 this.creationTime
= creationTime
;
76 this.oldestKeyTime
= oldestKeyTime
;
77 this.columnFamilyName
= columnFamilyName
;
78 this.filterPolicyName
= filterPolicyName
;
79 this.comparatorName
= comparatorName
;
80 this.mergeOperatorName
= mergeOperatorName
;
81 this.prefixExtractorName
= prefixExtractorName
;
82 this.propertyCollectorsNames
= propertyCollectorsNames
;
83 this.compressionName
= compressionName
;
84 this.userCollectedProperties
= userCollectedProperties
;
85 this.readableProperties
= readableProperties
;
86 this.propertiesOffsets
= propertiesOffsets
;
90 * Get the total size of all data blocks.
92 * @return the total size of all data blocks.
94 public long getDataSize() {
99 * Get the size of index block.
101 * @return the size of index block.
103 public long getIndexSize() {
108 * Get the total number of index partitions
109 * if {@link IndexType#kTwoLevelIndexSearch} is used.
111 * @return the total number of index partitions.
113 public long getIndexPartitions() {
114 return indexPartitions
;
118 * Size of the top-level index
119 * if {@link IndexType#kTwoLevelIndexSearch} is used.
121 * @return the size of the top-level index.
123 public long getTopLevelIndexSize() {
124 return topLevelIndexSize
;
128 * Whether the index key is user key.
129 * Otherwise it includes 8 byte of sequence
130 * number added by internal key format.
132 * @return the index key
134 public long getIndexKeyIsUserKey() {
135 return indexKeyIsUserKey
;
139 * Whether delta encoding is used to encode the index values.
141 * @return whether delta encoding is used to encode the index values.
143 public long getIndexValueIsDeltaEncoded() {
144 return indexValueIsDeltaEncoded
;
148 * Get the size of filter block.
150 * @return the size of filter block.
152 public long getFilterSize() {
157 * Get the total raw key size.
159 * @return the total raw key size.
161 public long getRawKeySize() {
166 * Get the total raw value size.
168 * @return the total raw value size.
170 public long getRawValueSize() {
175 * Get the number of blocks in this table.
177 * @return the number of blocks in this table.
179 public long getNumDataBlocks() {
180 return numDataBlocks
;
184 * Get the number of entries in this table.
186 * @return the number of entries in this table.
188 public long getNumEntries() {
193 * Get the number of deletions in the table.
195 * @return the number of deletions in the table.
197 public long getNumDeletions() {
202 * Get the number of merge operands in the table.
204 * @return the number of merge operands in the table.
206 public long getNumMergeOperands() {
207 return numMergeOperands
;
211 * Get the number of range deletions in this table.
213 * @return the number of range deletions in this table.
215 public long getNumRangeDeletions() {
216 return numRangeDeletions
;
220 * Get the format version, reserved for backward compatibility.
222 * @return the format version.
224 public long getFormatVersion() {
225 return formatVersion
;
229 * Get the length of the keys.
231 * @return 0 when the key is variable length, otherwise number of
232 * bytes for each key.
234 public long getFixedKeyLen() {
239 * Get the ID of column family for this SST file,
240 * corresponding to the column family identified by
241 * {@link #getColumnFamilyName()}.
243 * @return the id of the column family.
245 public long getColumnFamilyId() {
246 return columnFamilyId
;
250 * The time when the SST file was created.
251 * Since SST files are immutable, this is equivalent
252 * to last modified time.
254 * @return the created time.
256 public long getCreationTime() {
261 * Get the timestamp of the earliest key.
263 * @return 0 means unknown, otherwise the timestamp.
265 public long getOldestKeyTime() {
266 return oldestKeyTime
;
270 * Get the name of the column family with which this
271 * SST file is associated.
273 * @return the name of the column family, or null if the
274 * column family is unknown.
276 /*@Nullable*/ public byte[] getColumnFamilyName() {
277 return columnFamilyName
;
281 * Get the name of the filter policy used in this table.
283 * @return the name of the filter policy, or null if
284 * no filter policy is used.
286 /*@Nullable*/ public String
getFilterPolicyName() {
287 return filterPolicyName
;
291 * Get the name of the comparator used in this table.
293 * @return the name of the comparator.
295 public String
getComparatorName() {
296 return comparatorName
;
300 * Get the name of the merge operator used in this table.
302 * @return the name of the merge operator, or null if no merge operator
305 /*@Nullable*/ public String
getMergeOperatorName() {
306 return mergeOperatorName
;
310 * Get the name of the prefix extractor used in this table.
312 * @return the name of the prefix extractor, or null if no prefix
315 /*@Nullable*/ public String
getPrefixExtractorName() {
316 return prefixExtractorName
;
320 * Get the names of the property collectors factories used in this table.
322 * @return the names of the property collector factories separated
323 * by commas, e.g. {collector_name[1]},{collector_name[2]},...
325 public String
getPropertyCollectorsNames() {
326 return propertyCollectorsNames
;
330 * Get the name of the compression algorithm used to compress the SST files.
332 * @return the name of the compression algorithm.
334 public String
getCompressionName() {
335 return compressionName
;
339 * Get the user collected properties.
341 * @return the user collected properties.
343 public Map
<String
, String
> getUserCollectedProperties() {
344 return userCollectedProperties
;
348 * Get the readable properties.
350 * @return the readable properties.
352 public Map
<String
, String
> getReadableProperties() {
353 return readableProperties
;
357 * The offset of the value of each property in the file.
359 * @return the offset of each property.
361 public Map
<String
, Long
> getPropertiesOffsets() {
362 return propertiesOffsets
;
366 public boolean equals(Object o
) {
369 if (o
== null || getClass() != o
.getClass())
371 TableProperties that
= (TableProperties
) o
;
372 return dataSize
== that
.dataSize
&& indexSize
== that
.indexSize
373 && indexPartitions
== that
.indexPartitions
&& topLevelIndexSize
== that
.topLevelIndexSize
374 && indexKeyIsUserKey
== that
.indexKeyIsUserKey
375 && indexValueIsDeltaEncoded
== that
.indexValueIsDeltaEncoded
376 && filterSize
== that
.filterSize
&& rawKeySize
== that
.rawKeySize
377 && rawValueSize
== that
.rawValueSize
&& numDataBlocks
== that
.numDataBlocks
378 && numEntries
== that
.numEntries
&& numDeletions
== that
.numDeletions
379 && numMergeOperands
== that
.numMergeOperands
&& numRangeDeletions
== that
.numRangeDeletions
380 && formatVersion
== that
.formatVersion
&& fixedKeyLen
== that
.fixedKeyLen
381 && columnFamilyId
== that
.columnFamilyId
&& creationTime
== that
.creationTime
382 && oldestKeyTime
== that
.oldestKeyTime
383 && Arrays
.equals(columnFamilyName
, that
.columnFamilyName
)
384 && Objects
.equals(filterPolicyName
, that
.filterPolicyName
)
385 && Objects
.equals(comparatorName
, that
.comparatorName
)
386 && Objects
.equals(mergeOperatorName
, that
.mergeOperatorName
)
387 && Objects
.equals(prefixExtractorName
, that
.prefixExtractorName
)
388 && Objects
.equals(propertyCollectorsNames
, that
.propertyCollectorsNames
)
389 && Objects
.equals(compressionName
, that
.compressionName
)
390 && Objects
.equals(userCollectedProperties
, that
.userCollectedProperties
)
391 && Objects
.equals(readableProperties
, that
.readableProperties
)
392 && Objects
.equals(propertiesOffsets
, that
.propertiesOffsets
);
396 public int hashCode() {
397 int result
= Objects
.hash(dataSize
, indexSize
, indexPartitions
, topLevelIndexSize
,
398 indexKeyIsUserKey
, indexValueIsDeltaEncoded
, filterSize
, rawKeySize
, rawValueSize
,
399 numDataBlocks
, numEntries
, numDeletions
, numMergeOperands
, numRangeDeletions
, formatVersion
,
400 fixedKeyLen
, columnFamilyId
, creationTime
, oldestKeyTime
, filterPolicyName
, comparatorName
,
401 mergeOperatorName
, prefixExtractorName
, propertyCollectorsNames
, compressionName
,
402 userCollectedProperties
, readableProperties
, propertiesOffsets
);
403 result
= 31 * result
+ Arrays
.hashCode(columnFamilyName
);