|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.tsfile.file.metadata; |
| 21 | + |
| 22 | +import org.apache.tsfile.enums.TSDataType; |
| 23 | +import org.apache.tsfile.file.metadata.statistics.Statistics; |
| 24 | +import org.apache.tsfile.read.common.TimeRange; |
| 25 | +import org.apache.tsfile.read.controller.IChunkLoader; |
| 26 | + |
| 27 | +import java.io.OutputStream; |
| 28 | +import java.io.Serializable; |
| 29 | +import java.util.List; |
| 30 | +import java.util.Optional; |
| 31 | + |
| 32 | +public abstract class AbstractAlignedChunkMetadata implements IChunkMetadata { |
| 33 | + |
| 34 | + // ChunkMetadata for time column |
| 35 | + protected final IChunkMetadata timeChunkMetadata; |
| 36 | + // ChunkMetadata for all subSensors in the vector |
| 37 | + protected final List<IChunkMetadata> valueChunkMetadataList; |
| 38 | + |
| 39 | + /** ChunkLoader of metadata, used to create IChunkReader */ |
| 40 | + private IChunkLoader chunkLoader; |
| 41 | + |
| 42 | + AbstractAlignedChunkMetadata( |
| 43 | + IChunkMetadata timeChunkMetadata, List<IChunkMetadata> valueChunkMetadataList) { |
| 44 | + this.timeChunkMetadata = timeChunkMetadata; |
| 45 | + this.valueChunkMetadataList = valueChunkMetadataList; |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public Statistics<? extends Serializable> getTimeStatistics() { |
| 50 | + return timeChunkMetadata.getStatistics(); |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public Optional<Statistics<? extends Serializable>> getMeasurementStatistics( |
| 55 | + int measurementIndex) { |
| 56 | + IChunkMetadata chunkMetadata = valueChunkMetadataList.get(measurementIndex); |
| 57 | + return Optional.ofNullable(chunkMetadata == null ? null : chunkMetadata.getStatistics()); |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + public boolean hasNullValue(int measurementIndex) { |
| 62 | + long rowCount = getTimeStatistics().getCount(); |
| 63 | + Optional<Statistics<? extends Serializable>> statistics = |
| 64 | + getMeasurementStatistics(measurementIndex); |
| 65 | + return statistics.map(stat -> stat.hasNullValue(rowCount)).orElse(true); |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public int getMeasurementCount() { |
| 70 | + return valueChunkMetadataList.size(); |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + public boolean isModified() { |
| 75 | + return timeChunkMetadata.isModified(); |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + public void setModified(boolean modified) { |
| 80 | + timeChunkMetadata.setModified(modified); |
| 81 | + for (IChunkMetadata v : valueChunkMetadataList) { |
| 82 | + if (v != null) { |
| 83 | + v.setModified(modified); |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + @Override |
| 89 | + public boolean isSeq() { |
| 90 | + return timeChunkMetadata.isSeq(); |
| 91 | + } |
| 92 | + |
| 93 | + @Override |
| 94 | + public void setSeq(boolean seq) { |
| 95 | + timeChunkMetadata.setSeq(seq); |
| 96 | + for (IChunkMetadata v : valueChunkMetadataList) { |
| 97 | + if (v != null) { |
| 98 | + v.setSeq(seq); |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + @Override |
| 104 | + public long getVersion() { |
| 105 | + return timeChunkMetadata.getVersion(); |
| 106 | + } |
| 107 | + |
| 108 | + @Override |
| 109 | + public void setVersion(long version) { |
| 110 | + timeChunkMetadata.setVersion(version); |
| 111 | + for (IChunkMetadata valueChunkMetadata : valueChunkMetadataList) { |
| 112 | + if (valueChunkMetadata != null) { |
| 113 | + valueChunkMetadata.setVersion(version); |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + @Override |
| 119 | + public long getOffsetOfChunkHeader() { |
| 120 | + return timeChunkMetadata.getOffsetOfChunkHeader(); |
| 121 | + } |
| 122 | + |
| 123 | + @Override |
| 124 | + public long getStartTime() { |
| 125 | + return timeChunkMetadata.getStartTime(); |
| 126 | + } |
| 127 | + |
| 128 | + @Override |
| 129 | + public long getEndTime() { |
| 130 | + return timeChunkMetadata.getEndTime(); |
| 131 | + } |
| 132 | + |
| 133 | + @Override |
| 134 | + public IChunkLoader getChunkLoader() { |
| 135 | + return chunkLoader; |
| 136 | + } |
| 137 | + |
| 138 | + @Override |
| 139 | + public boolean needSetChunkLoader() { |
| 140 | + return chunkLoader == null; |
| 141 | + } |
| 142 | + |
| 143 | + @Override |
| 144 | + public void setChunkLoader(IChunkLoader chunkLoader) { |
| 145 | + this.chunkLoader = chunkLoader; |
| 146 | + } |
| 147 | + |
| 148 | + @Override |
| 149 | + public void setClosed(boolean closed) { |
| 150 | + timeChunkMetadata.setClosed(closed); |
| 151 | + for (IChunkMetadata chunkMetadata : valueChunkMetadataList) { |
| 152 | + if (chunkMetadata != null) { |
| 153 | + chunkMetadata.setClosed(closed); |
| 154 | + } |
| 155 | + } |
| 156 | + } |
| 157 | + |
| 158 | + @Override |
| 159 | + public TSDataType getDataType() { |
| 160 | + return timeChunkMetadata.getDataType(); |
| 161 | + } |
| 162 | + |
| 163 | + @Override |
| 164 | + public String getMeasurementUid() { |
| 165 | + return timeChunkMetadata.getMeasurementUid(); |
| 166 | + } |
| 167 | + |
| 168 | + @Override |
| 169 | + public void insertIntoSortedDeletions(TimeRange timeRange) { |
| 170 | + throw new UnsupportedOperationException(); |
| 171 | + } |
| 172 | + |
| 173 | + @Override |
| 174 | + public List<TimeRange> getDeleteIntervalList() { |
| 175 | + throw new UnsupportedOperationException(); |
| 176 | + } |
| 177 | + |
| 178 | + @Override |
| 179 | + public int serializeTo(OutputStream outputStream, boolean serializeStatistic) { |
| 180 | + throw new UnsupportedOperationException("VectorChunkMetadata doesn't support serial method"); |
| 181 | + } |
| 182 | + |
| 183 | + @Override |
| 184 | + public byte getMask() { |
| 185 | + return 0; |
| 186 | + } |
| 187 | + |
| 188 | + public IChunkMetadata getTimeChunkMetadata() { |
| 189 | + return timeChunkMetadata; |
| 190 | + } |
| 191 | + |
| 192 | + public List<IChunkMetadata> getValueChunkMetadataList() { |
| 193 | + return valueChunkMetadataList; |
| 194 | + } |
| 195 | +} |
0 commit comments