use of com.questdb.store.MMappedSymbolTable in project questdb by bluestreak01.
the class JoinQueryTest method generateJoinData.
private static void generateJoinData() throws JournalException, NumericException {
try (JournalWriter customers = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("customers").$int("customerId").$str("customerName").$str("contactName").$str("address").$str("city").$str("postalCode").$sym("country").$ts())) {
try (JournalWriter categories = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("categories").$sym("category").index().buckets(100).$str("description").$ts())) {
try (JournalWriter employees = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("employees").$str("employeeId").index().buckets(2048).$str("firstName").$str("lastName").$date("birthday").$ts())) {
try (JournalWriter orderDetails = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("orderDetails").$int("orderDetailId").$int("orderId").$int("productId").$int("quantity").$ts())) {
try (JournalWriter orders = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("orders").$int("orderId").$int("customerId").index().$int("productId").$str("employeeId").index().$ts("orderDate").$sym("shipper").$())) {
try (JournalWriter products = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("products").$int("productId").$str("productName").$sym("supplier").index().buckets(100).$sym("category").index().buckets(100).$double("price").$ts())) {
try (JournalWriter shippers = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("shippers").$sym("shipper").$str("phone").$ts())) {
try (JournalWriter suppliers = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("suppliers").$sym("supplier").buckets(100).$str("contactName").$str("address").$str("city").$str("postalCode").$sym("country").index().$str("phone").$ts())) {
final Rnd rnd = new Rnd();
long time = DateFormatUtils.parseDateTime("2015-07-10T00:00:00.000Z");
// statics
int countryCount = 196;
ObjList<String> countries = new ObjList<>();
for (int i = 0; i < countryCount; i++) {
countries.add(rnd.nextString(rnd.nextInt() & 15));
}
IntHashSet blackList = new IntHashSet();
// customers
int customerCount = 10000;
for (int i = 0; i < customerCount; i++) {
if (rnd.nextPositiveInt() % 100 == 0) {
blackList.add(i);
}
JournalEntryWriter w = customers.entryWriter();
w.putInt(0, i);
w.putStr(1, rnd.nextChars(rnd.nextInt() & 15));
w.putStr(2, rnd.nextChars(rnd.nextInt() & 31));
w.putStr(4, rnd.nextChars(rnd.nextInt() & 63));
w.putStr(5, rnd.nextChars(rnd.nextInt() & 15));
w.putSym(6, countries.getQuick(rnd.nextPositiveInt() % 196));
w.putDate(7, time++);
w.append();
}
customers.commit();
// categories
for (int i = 0; i < 100; i++) {
JournalEntryWriter w = categories.entryWriter();
w.putSym(0, rnd.nextChars(rnd.nextInt() & 15));
w.putStr(1, rnd.nextChars(rnd.nextInt() & 63));
w.putDate(2, time++);
w.append();
}
categories.commit();
// employees
int employeeCount = 2000;
for (int i = 0; i < employeeCount; i++) {
JournalEntryWriter w = employees.entryWriter();
w.putStr(0, rnd.nextChars(rnd.nextInt() & 7));
w.putStr(1, rnd.nextChars(rnd.nextInt() & 15));
w.putStr(2, rnd.nextChars(rnd.nextInt() & 15));
w.putDate(3, 0);
w.putDate(4, time++);
w.append();
}
employees.commit();
// suppliers
for (int i = 0; i < 100; i++) {
JournalEntryWriter w = suppliers.entryWriter();
w.putSym(0, rnd.nextChars(rnd.nextInt() & 15));
w.putStr(1, rnd.nextChars(rnd.nextInt() & 15));
w.putStr(2, rnd.nextChars(rnd.nextInt() & 15));
w.putStr(3, rnd.nextChars(rnd.nextInt() & 15));
w.putStr(4, rnd.nextChars(rnd.nextInt() & 7));
w.putSym(5, countries.getQuick(rnd.nextPositiveInt() % countryCount));
w.putStr(6, rnd.nextChars(rnd.nextInt() & 15));
w.putDate(7, time++);
w.append();
}
suppliers.commit();
MMappedSymbolTable categoryTab = categories.getSymbolTable("category");
int categoryTabSize = categoryTab.size();
MMappedSymbolTable supplierTab = suppliers.getSymbolTable("supplier");
int supplierTabSize = supplierTab.size();
// products
int productCount = 2000;
for (int i = 0; i < productCount; i++) {
JournalEntryWriter w = products.entryWriter();
w.putInt(0, i);
w.putStr(1, rnd.nextChars(rnd.nextInt() & 15));
w.putSym(2, supplierTab.value(rnd.nextPositiveInt() % supplierTabSize));
w.putSym(3, categoryTab.value(rnd.nextPositiveInt() % categoryTabSize));
w.putDouble(4, rnd.nextDouble());
w.putDate(5, time++);
w.append();
}
products.commit();
// shippers
for (int i = 0; i < 20; i++) {
JournalEntryWriter w = shippers.entryWriter();
w.putSym(0, rnd.nextChars(rnd.nextInt() & 15));
w.putStr(1, rnd.nextChars(rnd.nextInt() & 7));
w.append();
}
shippers.commit();
MMappedSymbolTable shipperTab = shippers.getSymbolTable("shipper");
int shipperTabSize = shipperTab.size();
int d = 0;
for (int i = 0; i < 100000; i++) {
int customerId = rnd.nextPositiveInt() % customerCount;
if (blackList.contains(customerId)) {
continue;
}
int orderId = rnd.nextPositiveInt();
JournalEntryWriter w = orders.entryWriter(time++);
w.putInt(0, orderId);
w.putInt(1, customerId);
w.putInt(2, rnd.nextPositiveInt() % productCount);
w.putStr(3, employees.getPartition(0, true).getFlyweightStr(rnd.nextPositiveLong() % employeeCount, 0));
w.putSym(5, shipperTab.value(rnd.nextPositiveInt() % shipperTabSize));
w.append();
int k = (rnd.nextInt() & 3) + 1;
for (int n = 0; n < k; n++) {
JournalEntryWriter dw = orderDetails.entryWriter();
dw.putInt(0, ++d);
dw.putInt(1, orderId);
dw.putInt(2, rnd.nextPositiveInt() % productCount);
dw.putInt(3, (rnd.nextInt() & 3) + 1);
dw.append();
}
}
orders.commit();
orderDetails.commit();
}
}
}
}
}
}
}
}
}
use of com.questdb.store.MMappedSymbolTable in project questdb by bluestreak01.
the class QueryAllBuilderImpl method setSymbol.
public void setSymbol(String symbol, String... values) {
this.symbol = symbol;
MMappedSymbolTable symbolTable = journal.getSymbolTable(symbol);
this.symbolKeys.clear();
for (int i = 0; i < values.length; i++) {
int key = symbolTable.getQuick(values[i]);
if (key != SymbolTable.VALUE_NOT_FOUND) {
symbolKeys.add(key);
}
}
}
use of com.questdb.store.MMappedSymbolTable in project questdb by bluestreak01.
the class QueryAllBuilderImpl method filter.
@Override
public QueryAllBuilder<T> filter(String symbol, CharSequence value) {
MMappedSymbolTable tab = journal.getSymbolTable(symbol);
int key = tab.get(value);
filterSymbols.add(symbol);
filterSymbolKeys.add(key);
return this;
}
use of com.questdb.store.MMappedSymbolTable in project questdb by bluestreak01.
the class JournalSymbolTableConsumer method commit.
@Override
protected void commit() {
for (int i = 0, sz = symbolTables.size(); i < sz; i++) {
MMappedSymbolTable tab = symbolTables.getQuick(i);
int oldSize = symbolTableSizes.getQuick(i);
tab.getDataColumn().commit();
tab.alignSize();
tab.updateIndex(oldSize, tab.size());
tab.commit();
}
}
use of com.questdb.store.MMappedSymbolTable in project questdb by bluestreak01.
the class JournalSymbolTableProducer method configure.
public void configure(Tx tx) {
hasContent = false;
buffer.rewind();
for (int i = 0, k = symbolTables.size(); i < k; i++) {
MMappedSymbolTable tab = symbolTables.getQuick(i);
if (tab != null) {
VariableColumnDeltaProducer p = symbolTableProducers.getQuick(i);
p.configure(i < tx.symbolTableSizes.length ? tx.symbolTableSizes[i] : 0, tab.size());
if (p.hasContent()) {
buffer.put((byte) 1);
hasContent = true;
} else {
buffer.put((byte) 0);
}
} else {
buffer.put((byte) 0);
}
}
}
Aggregations