use of io.questdb.std.datetime.DateFormat in project questdb by bluestreak01.
the class TableWriterTest method verifyTimestampPartitions.
void verifyTimestampPartitions(MemoryARW vmem) {
int i;
TimestampFormatCompiler compiler = new TimestampFormatCompiler();
DateFormat fmt = compiler.compile("yyyy-MM-dd");
DateLocale enGb = DateLocaleFactory.INSTANCE.getLocale("en-gb");
try (Path vp = new Path()) {
for (i = 0; i < 10000; i++) {
vp.of(root).concat(PRODUCT).slash();
fmt.format(vmem.getLong(i * 8L), enGb, "UTC", vp);
if (!FF.exists(vp.$())) {
Assert.fail();
}
}
}
}
use of io.questdb.std.datetime.DateFormat in project questdb by bluestreak01.
the class TableReaderTest method testRemovePartition.
private void testRemovePartition(int partitionBy, CharSequence partitionNameToDelete, int affectedBand, NextPartitionTimestampProvider provider) throws Exception {
TestUtils.assertMemoryLeak(() -> {
int N = 100;
int N_PARTITIONS = 5;
long timestampUs = TimestampFormatUtils.parseTimestamp("2017-12-11T10:00:00.000Z");
long stride = 100;
int bandStride = 1000;
int totalCount = 0;
// model table
try (TableModel model = new TableModel(configuration, "w", partitionBy).col("l", ColumnType.LONG).timestamp()) {
CairoTestUtils.create(model);
}
try (TableWriter writer = new TableWriter(configuration, "w")) {
for (int k = 0; k < N_PARTITIONS; k++) {
long band = k * bandStride;
for (int i = 0; i < N; i++) {
TableWriter.Row row = writer.newRow(timestampUs);
row.putLong(0, band + i);
row.append();
writer.commit();
timestampUs += stride;
}
timestampUs = provider.getNext(timestampUs);
}
Assert.assertEquals(N * N_PARTITIONS, writer.size());
DateFormat fmt = TableWriter.selectPartitionDirFmt(partitionBy);
assert fmt != null;
final long timestamp = fmt.parse(partitionNameToDelete, null);
Assert.assertTrue(writer.removePartition(timestamp));
Assert.assertFalse(writer.removePartition(timestamp));
Assert.assertEquals(N * (N_PARTITIONS - 1), writer.size());
}
// now open table reader having partition gap
try (TableReader reader = new TableReader(configuration, "w")) {
Assert.assertEquals(N * (N_PARTITIONS - 1), reader.size());
int previousBand = -1;
int bandCount = 0;
RecordCursor cursor = reader.getCursor();
final Record record = cursor.getRecord();
while (cursor.hasNext()) {
long value = record.getLong(0);
int band = (int) ((value / bandStride) * bandStride);
if (band != previousBand) {
// make sure we don#t pick up deleted partition
Assert.assertNotEquals(affectedBand, band);
if (previousBand != -1) {
Assert.assertEquals(N, bandCount);
}
previousBand = band;
bandCount = 0;
}
bandCount++;
totalCount++;
}
Assert.assertEquals(N, bandCount);
}
Assert.assertEquals(N * (N_PARTITIONS - 1), totalCount);
});
}
use of io.questdb.std.datetime.DateFormat in project questdb by bluestreak01.
the class TableReaderTest method testRemovePartitionReload.
private void testRemovePartitionReload(int partitionBy, CharSequence partitionNameToDelete, int affectedBand, NextPartitionTimestampProvider provider) throws Exception {
TestUtils.assertMemoryLeak(() -> {
int N = 100;
int N_PARTITIONS = 5;
long timestampUs = TimestampFormatUtils.parseTimestamp("2017-12-11T00:00:00.000Z");
long stride = 100;
int bandStride = 1000;
int totalCount = 0;
// model table
try (TableModel model = new TableModel(configuration, "w", partitionBy).col("l", ColumnType.LONG).timestamp()) {
CairoTestUtils.create(model);
}
try (TableWriter writer = new TableWriter(configuration, "w")) {
for (int k = 0; k < N_PARTITIONS; k++) {
long band = k * bandStride;
for (int i = 0; i < N; i++) {
TableWriter.Row row = writer.newRow(timestampUs);
row.putLong(0, band + i);
row.append();
writer.commit();
timestampUs += stride;
}
timestampUs = provider.getNext(timestampUs);
}
Assert.assertEquals(N * N_PARTITIONS, writer.size());
// now open table reader having partition gap
try (TableReader reader = new TableReader(configuration, "w")) {
Assert.assertEquals(N * N_PARTITIONS, reader.size());
RecordCursor cursor = reader.getCursor();
Record record = cursor.getRecord();
while (cursor.hasNext()) {
record.getLong(0);
totalCount++;
}
Assert.assertEquals(N * N_PARTITIONS, totalCount);
DateFormat fmt = TableWriter.selectPartitionDirFmt(partitionBy);
assert fmt != null;
Assert.assertTrue(writer.removePartition(fmt.parse(partitionNameToDelete, null)));
Assert.assertEquals(N * (N_PARTITIONS - 1), writer.size());
reader.reload();
totalCount = 0;
Assert.assertEquals(N * (N_PARTITIONS - 1), reader.size());
int previousBand = -1;
int bandCount = 0;
cursor = reader.getCursor();
record = cursor.getRecord();
while (cursor.hasNext()) {
long value = record.getLong(0);
int band = (int) ((value / bandStride) * bandStride);
if (band != previousBand) {
// make sure we don#t pick up deleted partition
Assert.assertNotEquals(affectedBand, band);
if (previousBand != -1) {
Assert.assertEquals(N, bandCount);
}
previousBand = band;
bandCount = 0;
}
bandCount++;
totalCount++;
}
Assert.assertEquals(N, bandCount);
}
}
Assert.assertEquals(N * (N_PARTITIONS - 1), totalCount);
});
}
use of io.questdb.std.datetime.DateFormat in project questdb by bluestreak01.
the class TableWriterTest method testSelectPartitionDirFmt.
@Test
public void testSelectPartitionDirFmt() {
Assert.assertNull(TableWriter.selectPartitionDirFmt(PartitionBy.NONE));
sink.clear();
DateFormat fmt = TableWriter.selectPartitionDirFmt(PartitionBy.DAY);
Assert.assertNotNull(fmt);
fmt.format(0, DateFormatUtils.enLocale, "Z", sink);
Assert.assertEquals("1970-01-01", sink.toString());
sink.clear();
fmt = TableWriter.selectPartitionDirFmt(PartitionBy.MONTH);
Assert.assertNotNull(fmt);
fmt.format(0, DateFormatUtils.enLocale, "Z", sink);
Assert.assertEquals("1970-01", sink.toString());
sink.clear();
fmt = TableWriter.selectPartitionDirFmt(PartitionBy.YEAR);
Assert.assertNotNull(fmt);
fmt.format(0, DateFormatUtils.enLocale, "Z", sink);
Assert.assertEquals("1970", sink.toString());
}
use of io.questdb.std.datetime.DateFormat in project questdb by bluestreak01.
the class DateFormatCompilerTest method testBasicParserCompiler.
@Test
public void testBasicParserCompiler() throws Exception {
DateFormat fmt = compiler.compile("E, dd MMM yyyy a KK:m:s.S Z");
String utcPattern = "yyyy-MM-ddTHH:mm:ss.SSSz";
DateFormat utc = compiler.compile(utcPattern);
long millis = fmt.parse("Mon, 08 Apr 2017 PM 11:11:10.123 UTC", defaultLocale);
sink.clear();
utc.format(millis, defaultLocale, "Z", sink);
TestUtils.assertEquals("2017-04-08T23:11:10.123Z", sink);
}
Aggregations