use of io.questdb.std.datetime.DateLocale in project questdb by bluestreak01.
the class TextMetadataParser method createImportedType.
private void createImportedType(int position) throws JsonException {
checkInputs(position, name, type);
columnNames.add(name);
switch(ColumnType.tagOf(type)) {
case ColumnType.DATE:
DateLocale dateLocale = locale == null ? this.dateLocale : dateLocaleFactory.getLocale(locale);
if (dateLocale == null) {
throw JsonException.$(localePosition, "Invalid date locale");
}
// date pattern is required
if (pattern == null) {
throw JsonException.$(0, "DATE format pattern is required");
}
columnTypes.add(typeManager.nextDateAdapter().of(dateFormatFactory.get(pattern), dateLocale));
break;
case ColumnType.TIMESTAMP:
DateLocale timestampLocale = locale == null ? this.dateLocale : dateLocaleFactory.getLocale(locale);
if (timestampLocale == null) {
throw JsonException.$(localePosition, "Invalid timestamp locale");
}
// timestamp pattern is required
if (pattern == null) {
throw JsonException.$(0, "TIMESTAMP format pattern is required");
}
columnTypes.add(typeManager.nextTimestampAdapter(utf8, timestampFormatFactory.get(pattern), timestampLocale));
break;
case ColumnType.SYMBOL:
columnTypes.add(typeManager.nextSymbolAdapter(index));
break;
default:
columnTypes.add(typeManager.getTypeAdapter(type));
break;
}
// prepare for next iteration
clearStage();
}
use of io.questdb.std.datetime.DateLocale 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.DateLocale in project questdb by bluestreak01.
the class TimestampsTest method testToTimezoneWithHoursInString.
@Test
public void testToTimezoneWithHoursInString() throws NumericException {
DateLocale locale = DateLocaleFactory.INSTANCE.getLocale("en");
long micros = TimestampFormatUtils.parseTimestamp("2019-12-10T10:00:00.000000Z");
long offsetMicros = Timestamps.toTimezone(micros, locale, "hello +03:45 there", 6, 12);
TestUtils.assertEquals("2019-12-10T13:45:00.000Z", Timestamps.toString(offsetMicros));
}
use of io.questdb.std.datetime.DateLocale in project questdb by bluestreak01.
the class TimestampsTest method testToTimezoneInvalidTimezoneName.
@Test(expected = NumericException.class)
public void testToTimezoneInvalidTimezoneName() throws NumericException {
DateLocale locale = DateLocaleFactory.INSTANCE.getLocale("en");
long micros = TimestampFormatUtils.parseTimestamp("2019-12-10T10:00:00.000000Z");
Timestamps.toTimezone(micros, locale, "Somewhere");
}
use of io.questdb.std.datetime.DateLocale in project questdb by bluestreak01.
the class TextLoaderTest method testDateFormatNoLocale.
@Test
public void testDateFormatNoLocale() throws Exception {
DateLocale locale = io.questdb.std.datetime.millitime.DateFormatUtils.enLocale;
assertNoLeak(textLoader -> {
String csv = "\"name\",\"date\"\n" + "\"Всероссийские спортивные соревнования школьников «ПРЕЗИДЕНТСКИЕ СОСТЯЗАНИЯ»\",\"3 " + locale.getMonth(6) + " 2017 г.\"\n" + "\"Всероссийские спортивные игры школьников «ПРЕЗИДЕНТСКИЕ СПОРТИВНЫЕ ИГРЫ»\",\"10 " + locale.getMonth(2) + " 2018 г.\"\n" + "\"Всероссийский летний ФЕСТИВАЛЬ ГТО\",\"28 " + locale.getMonth(1) + " 2016 г.\"\n";
String expected = "name\tdate\n" + "Всероссийские спортивные соревнования школьников «ПРЕЗИДЕНТСКИЕ СОСТЯЗАНИЯ»\t2017-07-03T00:00:00.000Z\n" + "Всероссийские спортивные игры школьников «ПРЕЗИДЕНТСКИЕ СПОРТИВНЫЕ ИГРЫ»\t2018-03-10T00:00:00.000Z\n" + "Всероссийский летний ФЕСТИВАЛЬ ГТО\t2016-02-28T00:00:00.000Z\n";
configureLoaderDefaults(textLoader, (byte) ',', Atomicity.SKIP_COL);
playJson(textLoader, ("[\n" + " {\n" + " \"name\": \"date\",\n" + " \"type\": \"DATE\",\n" + " \"pattern\": \"d MMMM y г.\"\n" + " }\n" + "]"));
textLoader.setForceHeaders(true);
textLoader.setState(TextLoader.ANALYZE_STRUCTURE);
playText0(textLoader, csv, 1024, ENTITY_MANIPULATOR);
sink.clear();
textLoader.getMetadata().toJson(sink);
TestUtils.assertEquals("{\"columnCount\":2,\"columns\":[{\"index\":0,\"name\":\"name\",\"type\":\"STRING\"},{\"index\":1,\"name\":\"date\",\"type\":\"DATE\"}],\"timestampIndex\":-1}", sink);
Assert.assertEquals(3L, textLoader.getParsedLineCount());
Assert.assertEquals(3L, textLoader.getWrittenLineCount());
assertTable(expected);
textLoader.clear();
});
}
Aggregations