use of com.questdb.std.IntList in project questdb by bluestreak01.
the class PlainTextDelimiterLexer method of.
@SuppressWarnings("ConstantConditions")
public void of(long address, int len) {
long lim = address + len;
long p = address;
boolean suspended = false;
int line = 0;
int comma = 0;
int pipe = 0;
int tab = 0;
int semicolon = 0;
// previous values
int _comma = 0;
int _pipe = 0;
int _tab = 0;
int _semicolon = 0;
commas.clear();
pipes.clear();
tabs.clear();
semicolons.clear();
this.avgRecLen = 0;
this.stdDev = Double.POSITIVE_INFINITY;
this.delimiter = 0;
boolean eol = false;
while (p < lim && line < maxLines) {
char b = (char) Unsafe.getUnsafe().getByte(p++);
if (suspended && b != '"') {
continue;
}
switch(b) {
case ',':
comma++;
if (eol) {
eol = false;
}
break;
case '|':
pipe++;
if (eol) {
eol = false;
}
break;
case '\t':
tab++;
if (eol) {
eol = false;
}
break;
case ';':
semicolon++;
if (eol) {
eol = false;
}
break;
case '"':
suspended = !suspended;
if (eol) {
eol = false;
}
break;
case '\n':
if (eol) {
break;
}
line++;
commas.add(comma - _comma);
pipes.add(pipe - _pipe);
tabs.add(tab - _tab);
semicolons.add(semicolon - _semicolon);
_comma = comma;
_pipe = pipe;
_tab = tab;
_semicolon = semicolon;
eol = true;
break;
default:
if (eol) {
eol = false;
}
break;
}
}
if (line == 0) {
return;
}
this.avgRecLen = len / line;
heap.clear();
heap.add(CSV, comma);
heap.add(PIPE, pipe);
heap.add(TAB, tab);
heap.add(';', semicolon);
this.delimiter = (char) heap.peekBottom();
IntList test;
switch(delimiter) {
case CSV:
test = commas;
break;
case PIPE:
test = pipes;
break;
case TAB:
test = tabs;
break;
case ';':
test = semicolons;
break;
default:
throw new IllegalArgumentException("Unsupported delimiter: " + delimiter);
}
// compute variance on test delimiter
double temp;
int n = test.size();
if (n == 0) {
delimiter = 0;
return;
}
temp = 0;
for (int i = 0; i < n; i++) {
temp += test.getQuick(i);
}
double mean = temp / n;
temp = 0;
for (int i = 0; i < n; i++) {
int v = test.getQuick(i);
temp += (mean - v) * (mean - v);
}
this.stdDev = Math.sqrt(temp / n);
}
Aggregations