use of com.questdb.BootstrapEnv in project questdb by bluestreak01.
the class ImportManager method analyzeAndParse.
private static void analyzeAndParse(File file, PlainTextLexer parser, MetadataAwareTextParser listener, CharSequence schema, int sampleSize, boolean forceHeader) throws IOException {
parser.clear();
ObjList<ImportedColumnMetadata> metadata = null;
if (schema != null) {
BootstrapEnv env = new BootstrapEnv();
env.dateLocaleFactory = new DateLocaleFactory(new TimeZoneRuleFactory());
env.dateFormatFactory = new DateFormatFactory();
JsonSchemaParser jsonSchemaParser = new JsonSchemaParser(env);
int len = schema.length();
long addr = Unsafe.malloc(len);
try {
Chars.strcpy(schema, len, addr);
try (JsonLexer lexer = new JsonLexer(1024, 4096)) {
lexer.parse(addr, len, jsonSchemaParser);
lexer.parseLast();
}
metadata = jsonSchemaParser.getMetadata();
} catch (JsonException e) {
throw new IOException(e);
} finally {
Unsafe.free(addr, len);
}
}
try (RandomAccessFile raf = new RandomAccessFile(file, "r")) {
try (FileChannel channel = raf.getChannel()) {
long size = channel.size();
long bufSize = ByteBuffers.getMaxMappedBufferSize(size);
long p = 0;
while (p < size) {
MappedByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, p, size - p < bufSize ? size - p : bufSize);
try {
if (p == 0) {
parser.analyseStructure(ByteBuffers.getAddress(buf), buf.remaining(), sampleSize, listener, forceHeader, metadata);
}
p += buf.remaining();
parser.parse(ByteBuffers.getAddress(buf), buf.remaining(), Integer.MAX_VALUE, listener);
} finally {
ByteBuffers.release(buf);
}
}
parser.parseLast();
}
}
}
Aggregations