Skip to content

Commit

Permalink
add more test
Browse files Browse the repository at this point in the history
  • Loading branch information
jt2594838 committed Jan 13, 2025
1 parent e0c37ac commit 8faf343
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import static org.apache.iotdb.relational.it.session.IoTDBSessionRelationalIT.genValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;

@RunWith(IoTDBTestRunner.class)
Expand Down Expand Up @@ -336,6 +337,19 @@ public void testDropAndAlter() throws IoTDBConnectionException, StatementExecuti
session.insert(tablet);
tablet.reset();

session.executeNonQueryStatement("FLUSH");

tablet =
new Tablet(
"drop_and_alter",
Collections.singletonList("s1"),
Collections.singletonList(TSDataType.INT32),
Collections.singletonList(ColumnCategory.FIELD));
tablet.addTimestamp(0, 2);
tablet.addValue("s1", 0, genValue(TSDataType.INT32, 2));
session.insert(tablet);
tablet.reset();

session.executeNonQueryStatement("ALTER TABLE drop_and_alter DROP COLUMN s1");

tablet =
Expand All @@ -344,8 +358,21 @@ public void testDropAndAlter() throws IoTDBConnectionException, StatementExecuti
Collections.singletonList("s1"),
Collections.singletonList(TSDataType.STRING),
Collections.singletonList(ColumnCategory.FIELD));
tablet.addTimestamp(0, 2);
tablet.addValue("s1", 0, genValue(TSDataType.STRING, 2));
tablet.addTimestamp(0, 3);
tablet.addValue("s1", 0, genValue(TSDataType.STRING, 3));
session.insert(tablet);
tablet.reset();

session.executeNonQueryStatement("FLUSH");

tablet =
new Tablet(
"drop_and_alter",
Collections.singletonList("s1"),
Collections.singletonList(TSDataType.STRING),
Collections.singletonList(ColumnCategory.FIELD));
tablet.addTimestamp(0, 4);
tablet.addValue("s1", 0, genValue(TSDataType.STRING, 4));
session.insert(tablet);
tablet.reset();

Expand All @@ -358,19 +385,37 @@ public void testDropAndAlter() throws IoTDBConnectionException, StatementExecuti
Collections.singletonList("s1"),
Collections.singletonList(TSDataType.TEXT),
Collections.singletonList(ColumnCategory.FIELD));
tablet.addTimestamp(0, 3);
tablet.addValue("s1", 0, genValue(TSDataType.STRING, 3));
tablet.addTimestamp(0, 5);
tablet.addValue("s1", 0, genValue(TSDataType.STRING, 5));
session.insert(tablet);
tablet.reset();

session.executeNonQueryStatement("FLUSH");

tablet =
new Tablet(
"drop_and_alter",
Collections.singletonList("s1"),
Collections.singletonList(TSDataType.TEXT),
Collections.singletonList(ColumnCategory.FIELD));
tablet.addTimestamp(0, 6);
tablet.addValue("s1", 0, genValue(TSDataType.STRING, 6));
session.insert(tablet);
tablet.reset();

SessionDataSet dataSet =
session.executeQueryStatement("select * from drop_and_alter order by time");
RowRecord rec = dataSet.next();
assertEquals(2, rec.getFields().get(0).getLongV());
assertEquals(genValue(TSDataType.STRING, 2).toString(), rec.getFields().get(1).toString());
rec = dataSet.next();
assertEquals(3, rec.getFields().get(0).getLongV());
assertEquals(genValue(TSDataType.STRING, 3).toString(), rec.getFields().get(1).toString());
RowRecord rec;
for (int i = 1; i < 3; i++) {
rec = dataSet.next();
assertEquals(i, rec.getFields().get(0).getLongV());
assertNull(rec.getFields().get(1).getDataType());
}
for (int i = 3; i < 7; i++) {
rec = dataSet.next();
assertEquals(i, rec.getFields().get(0).getLongV());
assertEquals(genValue(TSDataType.STRING, i).toString(), rec.getFields().get(1).toString());
}
assertFalse(dataSet.hasNext());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@
import org.apache.iotdb.db.queryengine.execution.exchange.sink.LocalSinkChannel;
import org.apache.iotdb.db.queryengine.execution.exchange.source.LocalSourceHandle;
import org.apache.iotdb.db.queryengine.execution.memory.LocalMemoryManager;
import org.apache.iotdb.db.utils.CommonUtils;
import org.apache.iotdb.mpp.rpc.thrift.TFragmentInstanceId;

import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import org.apache.commons.lang3.Validate;
import org.apache.tsfile.block.column.Column;
import org.apache.tsfile.read.common.block.TsBlock;
import org.apache.tsfile.read.common.block.column.TimeColumn;
import org.apache.tsfile.utils.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -216,19 +215,9 @@ public TsBlock remove() {
* the returned future of last invocation completes.
*/
public ListenableFuture<Void> add(TsBlock tsBlock) {
StringBuilder tsBlockBuilder = new StringBuilder();
for (Column column : tsBlock.getAllColumns()) {
tsBlockBuilder.append("[");
for (int i = 0; i < column.getPositionCount(); i++) {
if (column instanceof TimeColumn) {
tsBlockBuilder.append(column.getLong(i)).append(",");
} else {
tsBlockBuilder.append(column.getTsPrimitiveType(i)).append(",");
}
}
tsBlockBuilder.append("] ");
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("[addTsBlock] TsBlock:{}", CommonUtils.toString(tsBlock));
}
LOGGER.warn("[addTsBlock] TsBlock:{}", tsBlockBuilder);
if (closed) {
// queue may have been closed
return immediateVoidFuture();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@
import org.apache.iotdb.db.queryengine.execution.exchange.MPPDataExchangeManager.SourceHandleListener;
import org.apache.iotdb.db.queryengine.execution.exchange.SharedTsBlockQueue;
import org.apache.iotdb.db.queryengine.metric.DataExchangeCostMetricSet;
import org.apache.iotdb.db.utils.CommonUtils;
import org.apache.iotdb.db.utils.SetThreadName;
import org.apache.iotdb.mpp.rpc.thrift.TFragmentInstanceId;
import org.apache.iotdb.rpc.TSStatusCode;

import com.google.common.util.concurrent.ListenableFuture;
import org.apache.commons.lang3.Validate;
import org.apache.tsfile.block.column.Column;
import org.apache.tsfile.read.common.block.TsBlock;
import org.apache.tsfile.read.common.block.column.TimeColumn;
import org.apache.tsfile.read.common.block.column.TsBlockSerde;
import org.apache.tsfile.utils.RamUsageEstimator;
import org.slf4j.Logger;
Expand Down Expand Up @@ -143,19 +142,10 @@ public TsBlock receive() {
@Override
public ByteBuffer getSerializedTsBlock() throws IoTDBException {
TsBlock tsBlock = receive();
StringBuilder tsBlockBuilder = new StringBuilder();
for (Column column : tsBlock.getAllColumns()) {
tsBlockBuilder.append("[");
for (int i = 0; i < column.getPositionCount(); i++) {
if (column instanceof TimeColumn) {
tsBlockBuilder.append(column.getLong(i)).append(",");
} else {
tsBlockBuilder.append(column.getTsPrimitiveType(i)).append(",");
}
}
tsBlockBuilder.append("] ");
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("[GetSerializedTsBlock] TsBlock:{}", CommonUtils.toString(tsBlock));
}
LOGGER.warn("[GetSerializedTsBlock] TsBlock:{}", tsBlockBuilder);

if (tsBlock != null) {
long startTime = System.nanoTime();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.iotdb.db.storageengine.dataregion.read.reader.common.MergeReaderPriority;
import org.apache.iotdb.db.storageengine.dataregion.read.reader.common.PriorityMergeReader;
import org.apache.iotdb.db.storageengine.dataregion.tsfile.TsFileResource;
import org.apache.iotdb.db.utils.CommonUtils;

import org.apache.tsfile.block.column.Column;
import org.apache.tsfile.enums.TSDataType;
Expand Down Expand Up @@ -1317,7 +1318,9 @@ TsBlock getAllSatisfiedPageData(boolean ascending) throws IOException {
}
tsBlockBuilder.append("] ");
}
LOGGER.warn("[getAllSatisfiedPageData] TsBlock:{}", tsBlockBuilder);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("[getAllSatisfiedPageData] TsBlock:{}", CommonUtils.toString(tsBlock));
}
return tsBlock;
} finally {
long time = System.nanoTime() - startTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ public long getLastPoint() {

@Override
public boolean isEmpty() {
return list.rowCount() == 0 || measurementIndexMap.isEmpty();
return list.rowCount() == 0 || measurementIndexMap.isEmpty() && ignoreAllNullRows;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package org.apache.iotdb.db.storageengine.dataregion.read.reader.chunk;

import org.apache.iotdb.db.utils.CommonUtils;

import org.apache.tsfile.block.column.Column;
import org.apache.tsfile.block.column.ColumnBuilder;
import org.apache.tsfile.enums.TSDataType;
Expand All @@ -28,7 +30,6 @@
import org.apache.tsfile.read.common.BatchDataFactory;
import org.apache.tsfile.read.common.block.TsBlock;
import org.apache.tsfile.read.common.block.TsBlockBuilder;
import org.apache.tsfile.read.common.block.column.TimeColumn;
import org.apache.tsfile.read.filter.basic.Filter;
import org.apache.tsfile.read.filter.factory.FilterFactory;
import org.apache.tsfile.read.reader.IPageReader;
Expand Down Expand Up @@ -99,19 +100,9 @@ public TsBlock getAllSatisfiedData() {

// build value column
buildValueColumns(satisfyInfo, readEndIndex);
StringBuilder tsBlockBuilder = new StringBuilder();
for (Column column : tsBlock.getAllColumns()) {
tsBlockBuilder.append("[");
for (int i = 0; i < column.getPositionCount(); i++) {
if (column instanceof TimeColumn) {
tsBlockBuilder.append(column.getLong(i)).append(",");
} else {
tsBlockBuilder.append(column.getTsPrimitiveType(i)).append(",");
}
}
tsBlockBuilder.append("] ");
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("[memAlignedPageReader] TsBlock:{}", CommonUtils.toString(tsBlock));
}
LOGGER.warn("[memAlignedPageReader] TsBlock:{}", tsBlockBuilder);
return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@
import io.airlift.airline.ParseOptionMissingException;
import io.airlift.airline.ParseOptionMissingValueException;
import org.apache.commons.lang3.StringUtils;
import org.apache.tsfile.block.column.Column;
import org.apache.tsfile.common.conf.TSFileConfig;
import org.apache.tsfile.enums.TSDataType;
import org.apache.tsfile.file.metadata.IDeviceID;
import org.apache.tsfile.read.common.block.TsBlock;
import org.apache.tsfile.read.common.block.column.TimeColumn;
import org.apache.tsfile.utils.Binary;
import org.apache.tsfile.write.UnSupportedDataTypeException;

Expand Down Expand Up @@ -433,4 +436,20 @@ public static void addQueryLatency(StatementType statementType, long costTimeInN
Tag.TYPE.toString(),
statementType.name());
}

public static String toString(TsBlock tsBlock) {
StringBuilder tsBlockBuilder = new StringBuilder();
for (Column column : tsBlock.getAllColumns()) {
tsBlockBuilder.append("[");
for (int i = 0; i < column.getPositionCount(); i++) {
if (column instanceof TimeColumn) {
tsBlockBuilder.append(column.getLong(i)).append(",");
} else {
tsBlockBuilder.append(column.getTsPrimitiveType(i)).append(",");
}
}
tsBlockBuilder.append("] ");
}
return tsBlockBuilder.toString();
}
}

0 comments on commit 8faf343

Please sign in to comment.