Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

import org.apache.tsfile.annotations.TsFileApi;
import org.apache.tsfile.file.metadata.TableSchema;
import org.apache.tsfile.write.schema.IMeasurementSchema;

import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -66,5 +69,13 @@ private void validateParameters() {
if (this.memoryThresholdInByte <= 0) {
throw new IllegalArgumentException("Memory threshold must be > 0 bytes.");
}
if (StringUtils.isBlank(this.tableSchema.getTableName())) {
throw new IllegalArgumentException("TableName must not be blank.");
}
for (IMeasurementSchema columnSchema : this.tableSchema.getColumnSchemas()) {
if (columnSchema == null || StringUtils.isBlank(columnSchema.getMeasurementName())) {
throw new IllegalArgumentException("Column name must not be blank.");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,33 @@ public void testGetTableDeviceMethods() throws Exception {
Files.deleteIfExists(Paths.get(filePath));
}
}

@Test
public void testInvalidColumnNameOrTableName() throws Exception {
String filePath = TsFileGeneratorForTest.getTestTsFilePath("db", 0, 0, 0);

TableSchema tableSchema =
new TableSchema(
"",
Arrays.asList(
new MeasurementSchema("", TSDataType.STRING),
new MeasurementSchema("id2", TSDataType.STRING),
new MeasurementSchema("id3", TSDataType.STRING),
new MeasurementSchema("s1", TSDataType.INT32)),
Arrays.asList(
ColumnCategory.TAG, ColumnCategory.TAG, ColumnCategory.TAG, ColumnCategory.FIELD));
try (ITsFileWriter writer =
new TsFileWriterBuilder().file(new File(filePath)).tableSchema(tableSchema).build()) {
Assert.fail();
} catch (Exception e) {
Assert.assertTrue(e.getMessage().contains("TableName must not be blank."));
}
tableSchema.setTableName("table1");
try (ITsFileWriter writer =
new TsFileWriterBuilder().file(new File(filePath)).tableSchema(tableSchema).build()) {
Assert.fail();
} catch (Exception e) {
Assert.assertTrue(e.getMessage().contains("Column name must not be blank."));
}
}
}