use of com.questdb.parser.plaintext.PlainTextLexer in project questdb by bluestreak01.
the class ImportManager method importFile.
public static void importFile(Factory factory, String fileName, char delimiter, CharSequence schema, int sampleSize, boolean forceHeader) throws IOException {
BootstrapEnv env = new BootstrapEnv();
env.typeProbeCollection = new TypeProbeCollection();
env.configuration = new ServerConfiguration();
env.factory = factory;
try (PlainTextLexer parser = new PlainTextLexer(env).of(delimiter)) {
File file = new File(fileName);
String location = file.getName();
switch(factory.getConfiguration().exists(location)) {
case JournalConfiguration.EXISTS_FOREIGN:
throw new JournalRuntimeException("A foreign file/directory already exists: " + (new File(factory.getConfiguration().getJournalBase(), location)));
default:
try (PlainTextStoringParser l = new PlainTextStoringParser(env).of(location, false, false, PlainTextStoringParser.ATOMICITY_RELAXED)) {
analyzeAndParse(file, parser, l, schema, sampleSize, forceHeader);
}
break;
}
}
}
use of com.questdb.parser.plaintext.PlainTextLexer in project questdb by bluestreak01.
the class CsvTest method testHeaders.
@Test
public void testHeaders() throws Exception {
final List<String> names = new ArrayList<>();
final List<String> expected = new ArrayList<String>() {
{
add("type");
add("value");
add("active");
add("desc");
add("grp");
}
};
ImportManager.parse(new File(this.getClass().getResource("/csv/test-headers.csv").getFile()), new PlainTextLexer(env).of(','), 1024 * 1024, true, new PlainTextParser() {
@Override
public void onError(int line) {
}
@Override
public void onFieldCount(int count) {
}
@Override
public void onFields(int line, ObjList<DirectByteCharSequence> values, int hi) {
}
@Override
public void onHeader(ObjList<DirectByteCharSequence> values, int hi) {
for (int i = 0; i < hi; i++) {
names.add(values.getQuick(i).toString());
}
}
@Override
public void onLineCount(int count) {
}
});
TestUtils.assertEquals(expected.iterator(), names.iterator());
}
Aggregations