com.teradata.tpcds.Session Java Examples
The following examples show how to use
com.teradata.tpcds.Session.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HouseholdDemographicsRowGenerator.java From tpcds with Apache License 2.0 | 6 votes |
@Override public RowGeneratorResult generateRowAndChildRows(long rowNumber, Session session, RowGenerator parentRowGenerator, RowGenerator childRowGenerator) { long nullBitMap = createNullBitMap(HOUSEHOLD_DEMOGRAPHICS, getRandomNumberStream(HD_NULLS)); long hdDemoSk = rowNumber; long index = hdDemoSk; long hdIncomeBandId = (index % INCOME_BAND_DISTRIBUTION.getSize()) + 1; index /= INCOME_BAND_DISTRIBUTION.getSize(); String hdBuyPotential = getBuyPotentialForIndexModSize(index); index /= BUY_POTENTIAL_DISTRIBUTION.getSize(); int hdDepCount = getDepCountForIndexModSize(index); index /= DEP_COUNT_DISTRIBUTION.getSize(); int hdVehicleCount = getVehicleCountForIndexModSize(index); return new RowGeneratorResult(new HouseholdDemographicsRow(nullBitMap, hdDemoSk, hdIncomeBandId, hdBuyPotential, hdDepCount, hdVehicleCount)); }
Example #2
Source File: StoreSalesRowGenerator.java From tpcds with Apache License 2.0 | 6 votes |
public OrderInfo generateOrderInfo(long rowNumber, Session session) { // move to a new date if the row number is ahead of the nextDateIndex Scaling scaling = session.getScaling(); long ssSoldStoreSk = generateJoinKey(SS_SOLD_STORE_SK, getRandomNumberStream(SS_SOLD_STORE_SK), STORE, 1, scaling); long ssSoldTimeSk = generateJoinKey(SS_SOLD_TIME_SK, getRandomNumberStream(SS_SOLD_TIME_SK), TIME_DIM, 1, scaling); long ssSoldDateSk = generateJoinKey(SS_SOLD_DATE_SK, getRandomNumberStream(SS_SOLD_DATE_SK), DATE_DIM, 1, scaling); long ssSoldCustomerSk = generateJoinKey(SS_SOLD_CUSTOMER_SK, getRandomNumberStream(SS_SOLD_CUSTOMER_SK), CUSTOMER, 1, scaling); long ssSoldCdemoSk = generateJoinKey(SS_SOLD_CDEMO_SK, getRandomNumberStream(SS_SOLD_CDEMO_SK), CUSTOMER_DEMOGRAPHICS, 1, scaling); long ssSoldHdemoSk = generateJoinKey(SS_SOLD_HDEMO_SK, getRandomNumberStream(SS_SOLD_HDEMO_SK), HOUSEHOLD_DEMOGRAPHICS, 1, scaling); long ssSoldAddrSk = generateJoinKey(SS_SOLD_ADDR_SK, getRandomNumberStream(SS_SOLD_ADDR_SK), CUSTOMER_ADDRESS, 1, scaling); long ssTicketNumber = rowNumber; return new OrderInfo(ssSoldStoreSk, ssSoldTimeSk, ssSoldDateSk, ssSoldCustomerSk, ssSoldCdemoSk, ssSoldHdemoSk, ssSoldAddrSk, ssTicketNumber); }
Example #3
Source File: InventoryRowGenerator.java From tpcds with Apache License 2.0 | 6 votes |
@Override public RowGeneratorResult generateRowAndChildRows(long rowNumber, Session session, RowGenerator parentRowGenerator, RowGenerator childRowGenerator) { long nullBitMap = createNullBitMap(INVENTORY, getRandomNumberStream(INV_NULLS)); int index = (int) rowNumber - 1; Scaling scaling = session.getScaling(); long itemCount = scaling.getIdCount(ITEM); long invItemSk = (index % itemCount) + 1; index /= (int) itemCount; long warehouseCount = scaling.getIdCount(WAREHOUSE); long invWarehouseSk = (index % warehouseCount) + 1; index /= (int) warehouseCount; long invDateSk = JULIAN_DATE_MINIMUM + (index * 7); // inventory is updated weekly // The join between item and inventory is tricky. The item_id selected above identifies a unique part num // but item is a slowly changing dimension, so we need to account for that in selecting the surrogate key to join with invItemSk = SlowlyChangingDimensionUtils.matchSurrogateKey(invItemSk, invDateSk, ITEM, scaling); int invQuantityOnHand = generateUniformRandomInt(0, 1000, getRandomNumberStream(INV_QUANTITY_ON_HAND)); return new RowGeneratorResult(new InventoryRow(nullBitMap, invDateSk, invItemSk, invWarehouseSk, invQuantityOnHand)); }
Example #4
Source File: TimeDimRowGenerator.java From tpcds with Apache License 2.0 | 6 votes |
@Override public RowGeneratorResult generateRowAndChildRows(long rowNumber, Session session, RowGenerator parentRowGenerator, RowGenerator childRowGenerator) { long nullBitMap = createNullBitMap(TIME_DIM, getRandomNumberStream(T_NULLS)); long tTimeSk = rowNumber - 1; String tTimeId = makeBusinessKey(rowNumber); int tTime = (int) (rowNumber - 1); long timeTemp = tTime; int tSecond = (int) (timeTemp % 60); timeTemp /= 60; int tMinute = (int) (timeTemp % 60); timeTemp /= 60; int tHour = (int) (timeTemp % 24); HourInfo hourInfo = getHourInfoForHour(tHour); String tAmPm = hourInfo.getAmPm(); String tShift = hourInfo.getShift(); String tSubShift = hourInfo.getSubShift(); String tMealTime = hourInfo.getMeal(); return new RowGeneratorResult(new TimeDimRow(nullBitMap, tTimeSk, tTimeId, tTime, tHour, tMinute, tSecond, tAmPm, tShift, tSubShift, tMealTime)); }
Example #5
Source File: ShipModeRowGenerator.java From tpcds with Apache License 2.0 | 6 votes |
@Override public RowGeneratorResult generateRowAndChildRows(long rowNumber, Session session, RowGenerator parentRowGenerator, RowGenerator childRowGenerator) { long nullBitMap = createNullBitMap(SHIP_MODE, getRandomNumberStream(SM_NULLS)); long smShipModeSk = rowNumber; String smShipModeId = makeBusinessKey(rowNumber); long index = rowNumber; String smType = getShipModeTypeForIndexModSize(rowNumber); index /= SHIP_MODE_TYPE_DISTRIBUTION.getSize(); String smCode = getShipModeCodeForIndexModSize(index); String smCarrier = getShipModeCarrierAtIndex((int) (rowNumber) - 1); String smContract = generateRandomCharset(ALPHA_NUMERIC, 1, 20, getRandomNumberStream(SM_CONTRACT)); return new RowGeneratorResult(new ShipModeRow(nullBitMap, smShipModeSk, smShipModeId, smType, smCode, smCarrier, smContract)); }
Example #6
Source File: ReasonRowGenerator.java From tpcds with Apache License 2.0 | 5 votes |
@Override public RowGeneratorResult generateRowAndChildRows(long rowNumber, Session session, RowGenerator parentRowGenerator, RowGenerator childRowGenerator) { long nullBitMap = createNullBitMap(REASON, getRandomNumberStream(R_NULLS)); long rReasonSk = rowNumber; String rReasonId = makeBusinessKey(rowNumber); String rReasonDescription = getReturnReasonAtIndex((int) (rowNumber - 1)); return new RowGeneratorResult(new ReasonRow(nullBitMap, rReasonSk, rReasonId, rReasonDescription)); }
Example #7
Source File: WebReturnsRowGenerator.java From tpcds with Apache License 2.0 | 5 votes |
@Override public RowGeneratorResult generateRowAndChildRows(long rowNumber, Session session, RowGenerator parentRowGenerator, RowGenerator childRowGenerator) { RowGeneratorResult salesAndReturnsResult = parentRowGenerator.generateRowAndChildRows(rowNumber, session, null, this); if (salesAndReturnsResult.getRowAndChildRows().size() == 2) { return new RowGeneratorResult(ImmutableList.of(salesAndReturnsResult.getRowAndChildRows().get(1)), salesAndReturnsResult.shouldEndRow()); } else { return new RowGeneratorResult(emptyList(), salesAndReturnsResult.shouldEndRow()); // no return occurred for given sale } }
Example #8
Source File: WebSalesRowGenerator.java From tpcds with Apache License 2.0 | 5 votes |
private OrderInfo generateOrderInfo(long rowNumber, Session session) { Scaling scaling = session.getScaling(); long wsSoldDateSk = generateJoinKey(WS_SOLD_DATE_SK, getRandomNumberStream(WS_SOLD_DATE_SK), DATE_DIM, 1, scaling); long wsSoldTimeSk = generateJoinKey(WS_SOLD_TIME_SK, getRandomNumberStream(WS_SOLD_TIME_SK), TIME_DIM, 1, scaling); long wsBillCustomerSk = generateJoinKey(WS_BILL_CUSTOMER_SK, getRandomNumberStream(WS_BILL_CUSTOMER_SK), CUSTOMER, 1, scaling); long wsBillCdemoSk = generateJoinKey(WS_BILL_CDEMO_SK, getRandomNumberStream(WS_BILL_CDEMO_SK), CUSTOMER_DEMOGRAPHICS, 1, scaling); long wsBillHdemoSk = generateJoinKey(WS_BILL_HDEMO_SK, getRandomNumberStream(WS_BILL_HDEMO_SK), HOUSEHOLD_DEMOGRAPHICS, 1, scaling); long wsBillAddrSk = generateJoinKey(WS_BILL_ADDR_SK, getRandomNumberStream(WS_BILL_ADDR_SK), CUSTOMER_ADDRESS, 1, scaling); // Usually the billing info and shipping info are the same. If it's a gift, they'll be different. long wsShipCustomerSk = wsBillCustomerSk; long wsShipCdemoSk = wsBillCdemoSk; long wsShipHdemoSK = wsBillHdemoSk; long wsShipAddrSk = wsBillAddrSk; int randomInt = generateUniformRandomInt(0, 99, getRandomNumberStream(WS_SHIP_CUSTOMER_SK)); if (randomInt > GIFT_PERCENTAGE) { wsShipCustomerSk = generateJoinKey(WS_SHIP_CUSTOMER_SK, getRandomNumberStream(WS_SHIP_CUSTOMER_SK), CUSTOMER, 2, scaling); wsShipCdemoSk = generateJoinKey(WS_SHIP_CDEMO_SK, getRandomNumberStream(WS_SHIP_CDEMO_SK), CUSTOMER_DEMOGRAPHICS, 2, scaling); wsShipHdemoSK = generateJoinKey(WS_SHIP_HDEMO_SK, getRandomNumberStream(WS_SHIP_HDEMO_SK), HOUSEHOLD_DEMOGRAPHICS, 2, scaling); wsShipAddrSk = generateJoinKey(WS_SHIP_ADDR_SK, getRandomNumberStream(WS_SHIP_ADDR_SK), CUSTOMER_ADDRESS, 2, scaling); } long wsOrderNumber = rowNumber; return new OrderInfo(wsSoldDateSk, wsSoldTimeSk, wsBillCustomerSk, wsBillCdemoSk, wsBillHdemoSk, wsBillAddrSk, wsShipCustomerSk, wsShipCdemoSk, wsShipHdemoSK, wsShipAddrSk, wsOrderNumber); }
Example #9
Source File: TPCDSRecordHandler.java From aws-athena-query-federation with Apache License 2.0 | 5 votes |
/** * Generated TPCDS data for the given Table and scale factor as defined by the requested Split. * * @see RecordHandler */ @Override protected void readWithConstraint(BlockSpiller spiller, ReadRecordsRequest recordsRequest, QueryStatusChecker queryStatusChecker) throws IOException { Split split = recordsRequest.getSplit(); int splitNumber = Integer.parseInt(split.getProperty(SPLIT_NUMBER_FIELD)); int totalNumSplits = Integer.parseInt(split.getProperty(SPLIT_TOTAL_NUMBER_FIELD)); int scaleFactor = Integer.parseInt(split.getProperty(SPLIT_SCALE_FACTOR_FIELD)); Table table = validateTable(recordsRequest.getTableName()); Session session = Session.getDefaultSession() .withScale(scaleFactor) .withParallelism(totalNumSplits) .withChunkNumber(splitNumber + 1) .withTable(table) .withNoSexism(true); Results results = constructResults(table, session); Iterator<List<List<String>>> itr = results.iterator(); Map<Integer, CellWriter> writers = makeWriters(recordsRequest.getSchema(), table); while (itr.hasNext() && queryStatusChecker.isQueryRunning()) { List<String> row = itr.next().get(0); spiller.writeRows((Block block, int numRow) -> { boolean matched = true; for (Map.Entry<Integer, CellWriter> nextWriter : writers.entrySet()) { matched &= nextWriter.getValue().write(block, numRow, row.get(nextWriter.getKey())); } return matched ? 1 : 0; }); } }
Example #10
Source File: StoreReturnsRowGenerator.java From tpcds with Apache License 2.0 | 5 votes |
@Override public RowGeneratorResult generateRowAndChildRows(long rowNumber, Session session, RowGenerator parentRowGenerator, RowGenerator childRowGenerator) { // The store_returns table is a child of the store_sales table because you can only return things that have // already been purchased. This method should only get called if we are generating the store_returns table // in isolation. Otherwise store_returns is generated during the generation of the store_sales table RowGeneratorResult salesAndReturnsResult = parentRowGenerator.generateRowAndChildRows(rowNumber, session, null, this); if (salesAndReturnsResult.getRowAndChildRows().size() == 2) { return new RowGeneratorResult(ImmutableList.of(salesAndReturnsResult.getRowAndChildRows().get(1)), salesAndReturnsResult.shouldEndRow()); } else { return new RowGeneratorResult(emptyList(), salesAndReturnsResult.shouldEndRow()); // no return occurred for given sale } }
Example #11
Source File: WarehouseRowGenerator.java From tpcds with Apache License 2.0 | 5 votes |
@Override public RowGeneratorResult generateRowAndChildRows(long rowNumber, Session session, RowGenerator parentRowGenerator, RowGenerator childRowGenerator) { long nullBitMap = createNullBitMap(WAREHOUSE, getRandomNumberStream(W_NULLS)); long wWarehouseSk = rowNumber; String wWarehouseId = makeBusinessKey(rowNumber); String wWarehouseName = generateRandomText(10, 20, getRandomNumberStream(W_WAREHOUSE_NAME)); int wWarehouseSqFt = generateUniformRandomInt(50000, 1000000, getRandomNumberStream(W_WAREHOUSE_SQ_FT)); Address wAddress = makeAddressForColumn(WAREHOUSE, getRandomNumberStream(W_WAREHOUSE_ADDRESS), session.getScaling()); return new RowGeneratorResult(new WarehouseRow(nullBitMap, wWarehouseSk, wWarehouseId, wWarehouseName, wWarehouseSqFt, wAddress)); }
Example #12
Source File: CustomerDemographicsRowGenerator.java From tpcds with Apache License 2.0 | 5 votes |
@Override public RowGeneratorResult generateRowAndChildRows(long rowNumber, Session session, RowGenerator parentRowGenerator, RowGenerator childRowGenerator) { long nullBitMap = createNullBitMap(CUSTOMER_DEMOGRAPHICS, getRandomNumberStream(CD_NULLS)); long cDemoSk = rowNumber; long index = cDemoSk - 1; String cdGender = getGenderForIndexModSize(index); index = index / GENDER_DISTRIBUTION.getSize(); String cdMaritalStatus = getMaritalStatusForIndexModSize(index); index = index / MARITAL_STATUS_DISTRIBUTION.getSize(); String cdEducationStatus = getEducationForIndexModSize(index); index = index / EDUCATION_DISTRIBUTION.getSize(); int cdPurchaseEstimate = getPurchaseBandForIndexModSize(index); index = index / PURCHASE_BAND_DISTRIBUTION.getSize(); String cdCreditRating = getCreditRatingForIndexModSize(index); index = index / CREDIT_RATING_DISTRIBUTION.getSize(); int cdDepCount = (int) (index % (long) MAX_CHILDREN); index /= (long) MAX_CHILDREN; int cdEmployedCount = (int) (index % (long) MAX_EMPLOYED); index /= (long) MAX_EMPLOYED; int cdDepCollegeCount = (int) (index % (long) MAX_COLLEGE); return new RowGeneratorResult(new CustomerDemographicsRow(nullBitMap, cDemoSk, cdGender, cdMaritalStatus, cdEducationStatus, cdPurchaseEstimate, cdCreditRating, cdDepCount, cdEmployedCount, cdDepCollegeCount)); }
Example #13
Source File: CustomerAddressRowGenerator.java From tpcds with Apache License 2.0 | 5 votes |
@Override public RowGeneratorResult generateRowAndChildRows(long rowNumber, Session session, RowGenerator parentRowGenerator, RowGenerator childRowGenerator) { long nullBitMap = createNullBitMap(CUSTOMER_ADDRESS, getRandomNumberStream(CA_NULLS)); long caAddrSk = rowNumber; String caAddrId = makeBusinessKey(rowNumber); Address caAddr = makeAddressForColumn(CUSTOMER_ADDRESS, getRandomNumberStream(CA_ADDRESS), session.getScaling()); String caLocationType = pickRandomLocationType(getRandomNumberStream(CA_LOCATION_TYPE), UNIFORM); return new RowGeneratorResult(new CustomerAddressRow(nullBitMap, caAddrSk, caAddrId, caAddr, caLocationType)); }
Example #14
Source File: IncomeBandRowGenerator.java From tpcds with Apache License 2.0 | 5 votes |
@Override public RowGeneratorResult generateRowAndChildRows(long rowNumber, Session session, RowGenerator parentRowGenerator, RowGenerator childRowGenerator) { long nullBitMap = createNullBitMap(INCOME_BAND, getRandomNumberStream(IB_NULLS)); int ibIncomeBandId = (int) rowNumber; int ibLowerBound = getIncomeBandLowerBoundAtIndex((int) rowNumber - 1); int ibUpperBound = getIncomeBandUpperBoundAtIndex((int) rowNumber - 1); return new RowGeneratorResult(new IncomeBandRow(nullBitMap, ibIncomeBandId, ibLowerBound, ibUpperBound)); }
Example #15
Source File: DbgenVersionRowGenerator.java From tpcds with Apache License 2.0 | 5 votes |
@Override public RowGeneratorResult generateRowAndChildRows(long rowNumber, Session session, RowGenerator parentRowGenerator, RowGenerator childRowGenerator) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss"); Calendar calendar = Calendar.getInstance(); DbgenVersionRow row = new DbgenVersionRow( 0, DBGEN_VERSION, dateFormat.format(calendar.getTime()), timeFormat.format(calendar.getTime()), session.getCommandLineArguments()); return new RowGeneratorResult(row); }
Example #16
Source File: CatalogReturnsRowGenerator.java From tpcds with Apache License 2.0 | 5 votes |
@Override public RowGeneratorResult generateRowAndChildRows(long rowNumber, Session session, RowGenerator parentRowGenerator, RowGenerator childRowGenerator) { // The catalog returns table is a child of the catalog_sales table because you can only return things that have // already been purchased. This method should only get called if we are generating the catalog_returns table // in isolation. Otherwise catalog_returns is generated during the generation of the catalog_sales table RowGeneratorResult salesAndReturnsResult = parentRowGenerator.generateRowAndChildRows(rowNumber, session, null, this); if (salesAndReturnsResult.getRowAndChildRows().size() == 2) { return new RowGeneratorResult(ImmutableList.of(salesAndReturnsResult.getRowAndChildRows().get(1)), salesAndReturnsResult.shouldEndRow()); } else { return new RowGeneratorResult(emptyList(), salesAndReturnsResult.shouldEndRow()); // no return occurred for given sale } }
Example #17
Source File: TpcdsSchema.java From calcite with Apache License 2.0 | 5 votes |
public <T> Queryable<T> asQueryable(final QueryProvider queryProvider, final SchemaPlus schema, final String tableName) { //noinspection unchecked return (Queryable) new AbstractTableQueryable<Object[]>(queryProvider, schema, this, tableName) { public Enumerator<Object[]> enumerator() { final Session session = Session.getDefaultSession() .withTable(tpcdsTable) .withScale(scaleFactor); final Results results = Results.constructResults(tpcdsTable, session); return Linq4j.asEnumerable(results) .selectMany( new Function1<List<List<String>>, Enumerable<Object[]>>() { final Column[] columns = tpcdsTable.getColumns(); public Enumerable<Object[]> apply( List<List<String>> inRows) { final List<Object[]> rows = new ArrayList<>(); for (List<String> strings : inRows) { final Object[] values = new Object[columns.length]; for (int i = 0; i < strings.size(); i++) { values[i] = convert(strings.get(i), columns[i]); } rows.add(values); } return Linq4j.asEnumerable(rows); } }) .enumerator(); } }; }
Example #18
Source File: StoreReturnsRowGenerator.java From tpcds with Apache License 2.0 | 4 votes |
public TableRow generateRow(Session session, StoreSalesRow salesRow) { long nullBitMap = createNullBitMap(STORE_RETURNS, getRandomNumberStream(SR_NULLS)); // some of the information in the return is taken from the original sale long srTicketNumber = salesRow.getSsTicketNumber(); long srItemSk = salesRow.getSsSoldItemSk(); // some of the fields are conditionally taken from the sale Scaling scaling = session.getScaling(); long srCustomerSk = generateJoinKey(SR_CUSTOMER_SK, getRandomNumberStream(SR_CUSTOMER_SK), CUSTOMER, 1, scaling); int randomInt = generateUniformRandomInt(1, 100, getRandomNumberStream(SR_TICKET_NUMBER)); if (randomInt < SR_SAME_CUSTOMER) { srCustomerSk = salesRow.getSsSoldCustomerSk(); } // the rest of the columns are generated for this specific return long srReturnedDateSk = generateJoinKey(SR_RETURNED_DATE_SK, getRandomNumberStream(SR_RETURNED_DATE_SK), DATE_DIM, salesRow.getSsSoldDateSk(), scaling); long srReturnedTimeSk = generateUniformRandomInt(8 * 3600 - 1, 17 * 3600 - 1, getRandomNumberStream(SR_RETURNED_TIME_SK)); long srCdemoSk = generateJoinKey(SR_CDEMO_SK, getRandomNumberStream(SR_CDEMO_SK), CUSTOMER_DEMOGRAPHICS, 1, scaling); long srHdemoSk = generateJoinKey(SR_HDEMO_SK, getRandomNumberStream(SR_HDEMO_SK), HOUSEHOLD_DEMOGRAPHICS, 1, scaling); long srAddrSk = generateJoinKey(SR_ADDR_SK, getRandomNumberStream(SR_ADDR_SK), CUSTOMER_ADDRESS, 1, scaling); long srStoreSk = generateJoinKey(SR_STORE_SK, getRandomNumberStream(SR_STORE_SK), STORE, 1, scaling); long srReasonSk = generateJoinKey(SR_REASON_SK, getRandomNumberStream(SR_REASON_SK), REASON, 1, scaling); Pricing salesPricing = salesRow.getSsPricing(); int quantity = generateUniformRandomInt(1, salesPricing.getQuantity(), getRandomNumberStream(SR_PRICING)); Pricing srPricing = generatePricingForReturnsTable(SR_PRICING, getRandomNumberStream(SR_PRICING), quantity, salesPricing); return new StoreReturnsRow(nullBitMap, srReturnedDateSk, srReturnedTimeSk, srItemSk, srCustomerSk, srCdemoSk, srHdemoSk, srAddrSk, srStoreSk, srReasonSk, srTicketNumber, srPricing); }
Example #19
Source File: StoreSalesRowGenerator.java From tpcds with Apache License 2.0 | 4 votes |
@Override public RowGeneratorResult generateRowAndChildRows(long rowNumber, Session session, RowGenerator parentRowGenerator, RowGenerator childRowGenerator) { int itemCount = (int) session.getScaling().getIdCount(ITEM); if (itemPermutation == null) { itemPermutation = makePermutation(itemCount, getRandomNumberStream(SS_PERMUTATION)); } Scaling scaling = session.getScaling(); if (remainingLineItems == 0) { orderInfo = generateOrderInfo(rowNumber, session); remainingLineItems = generateUniformRandomInt(8, 16, getRandomNumberStream(SS_TICKET_NUMBER)); itemIndex = generateUniformRandomInt(1, (int) scaling.getIdCount(ITEM), getRandomNumberStream(SS_SOLD_ITEM_SK)); } long nullBitMap = createNullBitMap(STORE_SALES, getRandomNumberStream(SS_NULLS)); //items need to be unique within an order // use a sequence within the permutation if (++itemIndex > itemCount) { itemIndex = 1; } long ssSoldItemSk = matchSurrogateKey(getPermutationEntry(itemPermutation, itemIndex), orderInfo.getSsSoldDateSk(), ITEM, scaling); long ssSoldPromoSk = generateJoinKey(SS_SOLD_PROMO_SK, getRandomNumberStream(SS_SOLD_PROMO_SK), PROMOTION, 1, scaling); Pricing ssPricing = generatePricingForSalesTable(SS_PRICING, getRandomNumberStream(SS_PRICING)); StoreSalesRow storeSalesRow = new StoreSalesRow(nullBitMap, orderInfo.getSsSoldDateSk(), orderInfo.getSsSoldTimeSk(), ssSoldItemSk, orderInfo.getSsSoldCustomerSk(), orderInfo.getSsSoldCdemoSk(), orderInfo.getSsSoldHdemoSk(), orderInfo.getSsSoldAddrSk(), orderInfo.getSsSoldStoreSk(), ssSoldPromoSk, orderInfo.getSsTicketNumber(), ssPricing); List<TableRow> generatedRows = new ArrayList<>(2); generatedRows.add(storeSalesRow); // if the sale gets returned, generate a return row int randomInt = generateUniformRandomInt(0, 99, getRandomNumberStream(SR_IS_RETURNED)); if (randomInt < SR_RETURN_PCT && (!session.generateOnlyOneTable() || session.getOnlyTableToGenerate() != STORE_SALES)) { generatedRows.add(((StoreReturnsRowGenerator) childRowGenerator).generateRow(session, storeSalesRow)); } remainingLineItems--; return new RowGeneratorResult(generatedRows, isLastRowInOrder()); }
Example #20
Source File: CatalogReturnsRowGenerator.java From tpcds with Apache License 2.0 | 4 votes |
public TableRow generateRow(Session session, CatalogSalesRow salesRow) { long nullBitMap = createNullBitMap(CATALOG_RETURNS, getRandomNumberStream(CR_NULLS)); // some of the fields are conditionally taken from the sale Scaling scaling = session.getScaling(); long crReturningCustomerSk = generateJoinKey(CR_RETURNING_CUSTOMER_SK, getRandomNumberStream(CR_RETURNING_CUSTOMER_SK), CUSTOMER, 2, scaling); long crReturningCdemoSk = generateJoinKey(CR_RETURNING_CDEMO_SK, getRandomNumberStream(CR_RETURNING_CDEMO_SK), CUSTOMER_DEMOGRAPHICS, 2, scaling); long crReturningHdemoSk = generateJoinKey(CR_RETURNING_HDEMO_SK, getRandomNumberStream(CR_RETURNING_HDEMO_SK), HOUSEHOLD_DEMOGRAPHICS, 2, scaling); long crReturningAddrSk = generateJoinKey(CR_RETURNING_ADDR_SK, getRandomNumberStream(CR_RETURNING_ADDR_SK), CUSTOMER_ADDRESS, 2, scaling); if (generateUniformRandomInt(0, 99, getRandomNumberStream(CR_RETURNING_CUSTOMER_SK)) < CatalogSalesRowGenerator.GIFT_PERCENTAGE) { crReturningCustomerSk = salesRow.getCsShipCustomerSk(); crReturningCdemoSk = salesRow.getCsShipCdemoSk(); // skip crReturningHdemoSk, since it doesn't exist on the sales record crReturningAddrSk = salesRow.getCsShipAddrSk(); } Pricing salesPricing = salesRow.getCsPricing(); int quantity = salesPricing.getQuantity(); if (salesRow.getCsPricing().getQuantity() != -1) { quantity = generateUniformRandomInt(1, quantity, getRandomNumberStream(CR_PRICING)); } Pricing crPricing = generatePricingForReturnsTable(CR_PRICING, getRandomNumberStream(CR_PRICING), quantity, salesPricing); return new CatalogReturnsRow(generateJoinKey(CR_RETURNED_DATE_SK, getRandomNumberStream(CR_RETURNED_DATE_SK), DATE_DIM, salesRow.getCsShipDateSk(), scaling), // items cannot be returned until they are shipped generateJoinKey(CR_RETURNED_TIME_SK, getRandomNumberStream(CR_RETURNED_TIME_SK), TIME_DIM, 1, scaling), salesRow.getCsSoldItemSk(), salesRow.getCsBillCustomerSk(), salesRow.getCsBillCdemoSk(), salesRow.getCsBillHdemoSk(), salesRow.getCsBillAddrSk(), crReturningCustomerSk, crReturningCdemoSk, crReturningHdemoSk, crReturningAddrSk, salesRow.getCsCallCenterSk(), salesRow.getCsCatalogPageSk(), generateJoinKey(CR_SHIP_MODE_SK, getRandomNumberStream(CR_SHIP_MODE_SK), SHIP_MODE, 1, scaling), generateJoinKey(CR_WAREHOUSE_SK, getRandomNumberStream(CR_WAREHOUSE_SK), WAREHOUSE, 1, scaling), generateJoinKey(CR_REASON_SK, getRandomNumberStream(CR_REASON_SK), REASON, 1, scaling), salesRow.getCsOrderNumber(), crPricing, nullBitMap); }
Example #21
Source File: WebReturnsRowGenerator.java From tpcds with Apache License 2.0 | 4 votes |
public WebReturnsRow generateRow(Session session, WebSalesRow salesRow) { long nullBitMap = createNullBitMap(WEB_RETURNS, getRandomNumberStream(WR_NULLS)); // fields taken from the original sale long wrItemSk = salesRow.getWsItemSk(); long wrOrderNumber = salesRow.getWsOrderNumber(); long wrWebPageSk = salesRow.getWsWebPageSk(); // remaining fields are specific to this return Scaling scaling = session.getScaling(); long wrReturnedDateSk = generateJoinKey(WR_RETURNED_DATE_SK, getRandomNumberStream(WR_RETURNED_DATE_SK), DATE_DIM, salesRow.getWsShipDateSk(), scaling); long wrReturnedTimeSk = generateJoinKey(WR_RETURNED_TIME_SK, getRandomNumberStream(WR_RETURNED_TIME_SK), TIME_DIM, 1, scaling); // items are usually returned to the people they were shipped to, but sometimes not long wrRefundedCustomerSk = generateJoinKey(WR_REFUNDED_CUSTOMER_SK, getRandomNumberStream(WR_REFUNDED_CUSTOMER_SK), CUSTOMER, 1, scaling); long wrRefundedCdemoSk = generateJoinKey(WR_REFUNDED_CDEMO_SK, getRandomNumberStream(WR_REFUNDED_CDEMO_SK), CUSTOMER_DEMOGRAPHICS, 1, scaling); long wrRefundedHdemoSk = generateJoinKey(WR_REFUNDED_HDEMO_SK, getRandomNumberStream(WR_REFUNDED_HDEMO_SK), HOUSEHOLD_DEMOGRAPHICS, 1, scaling); long wrRefundedAddrSk = generateJoinKey(WR_REFUNDED_ADDR_SK, getRandomNumberStream(WR_REFUNDED_ADDR_SK), CUSTOMER_ADDRESS, 1, scaling); if (generateUniformRandomInt(0, 99, getRandomNumberStream(WR_RETURNING_CUSTOMER_SK)) < WebSalesRowGenerator.GIFT_PERCENTAGE) { wrRefundedCustomerSk = salesRow.getWsShipCustomerSk(); wrRefundedCdemoSk = salesRow.getWsShipCdemoSk(); wrRefundedHdemoSk = salesRow.getWsShipHdemoSk(); wrRefundedAddrSk = salesRow.getWsShipAddrSk(); } long wrReturningCustomerSk = wrRefundedCustomerSk; long wrReturningCdemoSk = wrRefundedCdemoSk; long wrReturningHdemoSk = wrRefundedHdemoSk; long wrReturningAddrSk = wrRefundedAddrSk; long wrReasonSk = generateJoinKey(WR_REASON_SK, getRandomNumberStream(WR_REASON_SK), REASON, 1, scaling); int quantity = generateUniformRandomInt(1, salesRow.getWsPricing().getQuantity(), getRandomNumberStream(WR_PRICING)); Pricing wrPricing = generatePricingForReturnsTable(WR_PRICING, getRandomNumberStream(WR_PRICING), quantity, salesRow.getWsPricing()); return new WebReturnsRow(nullBitMap, wrReturnedDateSk, wrReturnedTimeSk, wrItemSk, wrRefundedCustomerSk, wrRefundedCdemoSk, wrRefundedHdemoSk, wrRefundedAddrSk, wrReturningCustomerSk, wrReturningCdemoSk, wrReturningHdemoSk, wrReturningAddrSk, wrWebPageSk, wrReasonSk, wrOrderNumber, wrPricing); }
Example #22
Source File: CatalogSalesRowGenerator.java From tpcds with Apache License 2.0 | 4 votes |
private OrderInfo generateOrderInfo(long rowNumber, Session session) { Scaling scaling = session.getScaling(); // move to a new date if the row number is ahead of the nextDateIndex while (rowNumber > nextDateIndex) { julianDate += 1; nextDateIndex += scaling.getRowCountForDate(CATALOG_SALES, julianDate); } // Some attributes remain the same for each lineitem in an order; others are different // for each lineitem. // // Parallel generation causes another problem, since the values that get seeded may come from a prior row. // If we are seeding at the start of a parallel chunk, hunt backwards in the RNG stream to find the most // recent values that were used to set the values of the orderline-invariant columns long csSoldDateSk = julianDate; long csSoldTimeSk = generateJoinKey(CS_SOLD_TIME_SK, getRandomNumberStream(CS_SOLD_TIME_SK), TIME_DIM, orderInfo.getCsCallCenterSk(), scaling); long csCallCenterSk = (csSoldDateSk == -1) ? -1 : generateJoinKey(CS_CALL_CENTER_SK, getRandomNumberStream(CS_CALL_CENTER_SK), CALL_CENTER, csSoldDateSk, scaling); long csBillCustomerSk = generateJoinKey(CS_BILL_CUSTOMER_SK, getRandomNumberStream(CS_BILL_CUSTOMER_SK), CUSTOMER, 1, scaling); long csBillCdemoSk = generateJoinKey(CS_BILL_CDEMO_SK, getRandomNumberStream(CS_BILL_CDEMO_SK), CUSTOMER_DEMOGRAPHICS, 1, scaling); long csBillHdemoSk = generateJoinKey(CS_BILL_HDEMO_SK, getRandomNumberStream(CS_BILL_HDEMO_SK), HOUSEHOLD_DEMOGRAPHICS, 1, scaling); long csBillAddrSk = generateJoinKey(CS_BILL_ADDR_SK, getRandomNumberStream(CS_BILL_ADDR_SK), CUSTOMER_ADDRESS, 1, scaling); // most orders are for the ordering customers, some are not int giftPercentage = generateUniformRandomInt(0, 99, getRandomNumberStream(CS_SHIP_CUSTOMER_SK)); long csShipCustomerSk = csBillCustomerSk; long csShipCdemoSk = csBillCdemoSk; long csShipHdemoSk = csBillHdemoSk; long csShipAddrSk = csBillAddrSk; if (giftPercentage <= GIFT_PERCENTAGE) { csShipCustomerSk = generateJoinKey(CS_SHIP_CUSTOMER_SK, getRandomNumberStream(CS_SHIP_CUSTOMER_SK), CUSTOMER, 2, scaling); csShipCdemoSk = generateJoinKey(CS_SHIP_CDEMO_SK, getRandomNumberStream(CS_SHIP_CDEMO_SK), CUSTOMER_DEMOGRAPHICS, 2, scaling); csShipHdemoSk = generateJoinKey(CS_SHIP_HDEMO_SK, getRandomNumberStream(CS_SHIP_HDEMO_SK), HOUSEHOLD_DEMOGRAPHICS, 2, scaling); csShipAddrSk = generateJoinKey(CS_SHIP_ADDR_SK, getRandomNumberStream(CS_SHIP_ADDR_SK), CUSTOMER_ADDRESS, 2, scaling); } long csOrderNumber = rowNumber; return new OrderInfo(csSoldDateSk, csSoldTimeSk, csCallCenterSk, csBillCustomerSk, csBillCdemoSk, csBillHdemoSk, csBillAddrSk, csShipCustomerSk, csShipCdemoSk, csShipHdemoSk, csShipAddrSk, csOrderNumber); }
Example #23
Source File: CatalogSalesRowGenerator.java From tpcds with Apache License 2.0 | 4 votes |
@Override public RowGeneratorResult generateRowAndChildRows(long rowNumber, Session session, RowGenerator parentRowGenerator, RowGenerator childRowGenerator) { int itemCount = (int) session.getScaling().getIdCount(ITEM); if (itemPermutation == null) { itemPermutation = makePermutation(itemCount, getRandomNumberStream(CS_PERMUTE)); DateNextIndexPair pair = skipDaysUntilFirstRowOfChunk(CATALOG_SALES, session); julianDate = pair.getJulianDate(); nextDateIndex = pair.getNextDateIndex(); } if (remainingLineItems == 0) { orderInfo = generateOrderInfo(rowNumber, session); ticketItemBase = generateUniformRandomInt(1, itemCount, getRandomNumberStream(CS_SOLD_ITEM_SK)); remainingLineItems = generateUniformRandomInt(4, 14, getRandomNumberStream(CS_ORDER_NUMBER)); } long nullBitMap = createNullBitMap(CATALOG_SALES, getRandomNumberStream(CS_NULLS)); // orders are shipped some number of days after they are ordered int shippingLag = generateUniformRandomInt(CS_MIN_SHIP_DELAY, CS_MAX_SHIP_DELAY, getRandomNumberStream(CS_SHIP_DATE_SK)); long csShipDateSk = orderInfo.getCsSoldDateSk() == -1 ? -1 : orderInfo.getCsSoldDateSk() + shippingLag; // items need to be unique within an order // use a sequence within the permutation // NB: Permutations are 1-based if (++ticketItemBase > itemCount) { ticketItemBase = 1; } Scaling scaling = session.getScaling(); long item = getPermutationEntry(itemPermutation, ticketItemBase); long csSoldItemSk = matchSurrogateKey(item, orderInfo.getCsSoldDateSk(), ITEM, scaling); // catalog page needs to be from a catalog active at the time of the sale long csCatalogPageSk = (orderInfo.getCsSoldDateSk() == -1) ? -1 : generateJoinKey(CS_CATALOG_PAGE_SK, getRandomNumberStream(CS_CATALOG_PAGE_SK), CATALOG_PAGE, orderInfo.getCsSoldDateSk(), scaling); long csShipModeSk = generateJoinKey(CS_SHIP_MODE_SK, getRandomNumberStream(CS_SHIP_MODE_SK), SHIP_MODE, 1, scaling); long csWarehouseSk = generateJoinKey(CS_WAREHOUSE_SK, getRandomNumberStream(CS_WAREHOUSE_SK), WAREHOUSE, 1, scaling); long csPromoSk = generateJoinKey(CS_PROMO_SK, getRandomNumberStream(CS_PROMO_SK), PROMOTION, 1, scaling); Pricing csPricing = generatePricingForSalesTable(CS_PRICING, getRandomNumberStream(CS_PRICING)); CatalogSalesRow catalogSalesRow = new CatalogSalesRow(orderInfo.getCsSoldDateSk(), orderInfo.getCsSoldTimeSk(), csShipDateSk, orderInfo.getCsBillCustomerSk(), orderInfo.getCsBillCdemoSk(), orderInfo.getCsBillHdemoSk(), orderInfo.getCsBillAddrSk(), orderInfo.getCsShipCustomerSk(), orderInfo.getCsShipCdemoSk(), orderInfo.getCsShipHdemoSk(), orderInfo.getCsShipAddrSk(), orderInfo.getCsCallCenterSk(), csCatalogPageSk, csShipModeSk, csWarehouseSk, csSoldItemSk, csPromoSk, orderInfo.getCsOrderNumber(), csPricing, nullBitMap); List<TableRow> generatedRows = new ArrayList<>(2); generatedRows.add(catalogSalesRow); // if the sale gets returned, generate a return row int randomInt = generateUniformRandomInt(0, 99, getRandomNumberStream(CR_IS_RETURNED)); if (randomInt < CatalogReturnsRowGenerator.RETURN_PERCENT && (!session.generateOnlyOneTable() || session.getOnlyTableToGenerate() != CATALOG_SALES)) { TableRow catalogReturnsRow = ((CatalogReturnsRowGenerator) childRowGenerator).generateRow(session, catalogSalesRow); generatedRows.add(catalogReturnsRow); } remainingLineItems--; return new RowGeneratorResult(generatedRows, isLastRowInOrder()); }
Example #24
Source File: WebSalesRowGenerator.java From tpcds with Apache License 2.0 | 4 votes |
@Override public RowGeneratorResult generateRowAndChildRows(long rowNumber, Session session, RowGenerator parentRowGenerator, RowGenerator childRowGenerator) { Scaling scaling = session.getScaling(); int itemCount = (int) scaling.getIdCount(ITEM); if (itemPermutation == null) { itemPermutation = makePermutation(itemCount, getRandomNumberStream(WS_PERMUTATION)); } if (remainingLineItems == 0) { orderInfo = generateOrderInfo(rowNumber, session); itemIndex = generateUniformRandomInt(1, itemCount, getRandomNumberStream(WS_ITEM_SK)); remainingLineItems = generateUniformRandomInt(8, 16, getRandomNumberStream(WS_ORDER_NUMBER)); } long nullBitMap = createNullBitMap(WEB_SALES, getRandomNumberStream(WS_NULLS)); int shipLag = generateUniformRandomInt(1, 120, getRandomNumberStream(WS_SHIP_DATE_SK)); long wsShipDateSk = orderInfo.wsSoldDateSk + shipLag; if (++itemIndex > itemCount) { itemIndex = 1; } long wsItemSk = matchSurrogateKey(getPermutationEntry(itemPermutation, itemIndex), orderInfo.wsSoldDateSk, ITEM, scaling); // the web page needs to be valid for the sale date long wsWebPageSk = generateJoinKey(WS_WEB_PAGE_SK, getRandomNumberStream(WS_WEB_PAGE_SK), WEB_PAGE, orderInfo.wsSoldDateSk, scaling); long wsWebSiteSk = generateJoinKey(WS_WEB_SITE_SK, getRandomNumberStream(WS_WEB_SITE_SK), WEB_SITE, orderInfo.wsSoldDateSk, scaling); long wsShipModeSk = generateJoinKey(WS_SHIP_MODE_SK, getRandomNumberStream(WS_SHIP_MODE_SK), SHIP_MODE, 1, scaling); long wsWarehouseSk = generateJoinKey(WS_WAREHOUSE_SK, getRandomNumberStream(WS_WAREHOUSE_SK), WAREHOUSE, 1, scaling); long wsPromoSk = generateJoinKey(WS_PROMO_SK, getRandomNumberStream(WS_PROMO_SK), PROMOTION, 1, scaling); Pricing wsPricing = generatePricingForSalesTable(WS_PRICING, getRandomNumberStream(WS_PRICING)); WebSalesRow salesRow = new WebSalesRow(nullBitMap, orderInfo.wsSoldDateSk, orderInfo.wsSoldTimeSk, wsShipDateSk, wsItemSk, orderInfo.wsBillCustomerSk, orderInfo.wsBillCdemoSk, orderInfo.wsBillHdemoSk, orderInfo.wsBillAddrSk, orderInfo.wsShipCustomerSk, orderInfo.wsShipCdemoSk, orderInfo.wsShipHdemoSk, orderInfo.wsShipAddrSk, wsWebPageSk, wsWebSiteSk, wsShipModeSk, wsWarehouseSk, wsPromoSk, orderInfo.wsOrderNumber, wsPricing); List<TableRow> generatedRows = new ArrayList<>(2); generatedRows.add(salesRow); // if the item gets returned, generate a returns row int randomInt = generateUniformRandomInt(0, 99, getRandomNumberStream(WR_IS_RETURNED)); if (randomInt < RETURN_PERCENTAGE && (!session.generateOnlyOneTable() || !(session.getOnlyTableToGenerate() == WEB_SALES))) { TableRow returnsRow = ((WebReturnsRowGenerator) childRowGenerator).generateRow(session, salesRow); generatedRows.add(returnsRow); } remainingLineItems--; return new RowGeneratorResult(generatedRows, remainingLineItems == 0); }
Example #25
Source File: CustomerRowGenerator.java From tpcds with Apache License 2.0 | 4 votes |
@Override public RowGeneratorResult generateRowAndChildRows(long rowNumber, Session session, RowGenerator parentRowGenerator, RowGenerator childRowGenerator) { long cCustomerSk = rowNumber; String cCustomerId = makeBusinessKey(rowNumber); int randomInt = generateUniformRandomInt(1, 100, getRandomNumberStream(C_PREFERRED_CUST_FLAG)); int cPreferredPercent = 50; boolean cPreferredCustFlag = randomInt < cPreferredPercent; Scaling scaling = session.getScaling(); long cCurrentHdemoSk = generateJoinKey(C_CURRENT_HDEMO_SK, getRandomNumberStream(C_CURRENT_HDEMO_SK), HOUSEHOLD_DEMOGRAPHICS, 1, scaling); long cCurrentCdemoSk = generateJoinKey(C_CURRENT_CDEMO_SK, getRandomNumberStream(C_CURRENT_CDEMO_SK), CUSTOMER_DEMOGRAPHICS, 1, scaling); long cCurrentAddrSk = generateJoinKey(C_CURRENT_ADDR_SK, getRandomNumberStream(C_CURRENT_ADDR_SK), CUSTOMER_ADDRESS, cCustomerSk, scaling); int nameIndex = pickRandomIndex(GENERAL_FREQUENCY, getRandomNumberStream(C_FIRST_NAME)); String cFirstName = getFirstNameFromIndex(nameIndex); String cLastName = pickRandomLastName(getRandomNumberStream(C_LAST_NAME)); int femaleNameWeight = getWeightForIndex(nameIndex, FEMALE_FREQUENCY); String cSalutation = pickRandomSalutation(femaleNameWeight == 0 ? MALE : FEMALE, getRandomNumberStream(C_SALUTATION)); Date maxBirthday = new Date(1992, 12, 31); Date minBirthday = new Date(1924, 1, 1); Date oneYearAgo = fromJulianDays(JULIAN_TODAYS_DATE - 365); Date tenYearsAgo = fromJulianDays(JULIAN_TODAYS_DATE - 3650); Date today = fromJulianDays(JULIAN_TODAYS_DATE); Date birthday = generateUniformRandomDate(minBirthday, maxBirthday, getRandomNumberStream(C_BIRTH_DAY)); int cBirthDay = birthday.getDay(); int cBirthMonth = birthday.getMonth(); int cBirthYear = birthday.getYear(); String cEmailAddress = generateRandomEmail(cFirstName, cLastName, getRandomNumberStream(C_EMAIL_ADDRESS)); Date lastReviewDate = generateUniformRandomDate(oneYearAgo, today, getRandomNumberStream(C_LAST_REVIEW_DATE)); int cLastReviewDate = toJulianDays(lastReviewDate); Date firstSalesDate = generateUniformRandomDate(tenYearsAgo, today, getRandomNumberStream(C_FIRST_SALES_DATE_ID)); int cFirstSalesDateId = toJulianDays(firstSalesDate); int cFirstShiptoDateId = cFirstSalesDateId + 30; String cBirthCountry = pickRandomCountry(getRandomNumberStream(C_BIRTH_COUNTRY)); return new RowGeneratorResult(new CustomerRow(cCustomerSk, cCustomerId, cCurrentCdemoSk, cCurrentHdemoSk, cCurrentAddrSk, cFirstShiptoDateId, cFirstSalesDateId, cSalutation, cFirstName, cLastName, cPreferredCustFlag, cBirthDay, cBirthMonth, cBirthYear, cBirthCountry, cEmailAddress, cLastReviewDate, createNullBitMap(CUSTOMER, getRandomNumberStream(C_NULLS)))); }
Example #26
Source File: CatalogPageRowGenerator.java From tpcds with Apache License 2.0 | 4 votes |
@Override public RowGeneratorResult generateRowAndChildRows(long rowNumber, Session session, RowGenerator parentRowGenerator, RowGenerator childRowGenerator) { long cpCatalogPageSk = rowNumber; String cpDepartment = "DEPARTMENT"; long nullBitMap = createNullBitMap(CATALOG_PAGE, getRandomNumberStream(CP_NULLS)); String cpCatalogPageId = makeBusinessKey(rowNumber); int catalogPageMax = ((int) (session.getScaling().getRowCount(CATALOG_PAGE) / CATALOGS_PER_YEAR)) / (DATE_MAXIMUM.getYear() - DATE_MINIMUM.getYear() + 2); int cpCatalogNumber = (int) ((rowNumber - 1) / catalogPageMax + 1); int cpCatalogPageNumber = (int) ((rowNumber - 1) % catalogPageMax + 1); int catalogInterval = (cpCatalogNumber - 1) % CATALOGS_PER_YEAR; String cpType; int duration; int offset; switch (catalogInterval) { case 0: case 1: cpType = "bi-annual"; duration = 182; offset = catalogInterval * duration; break; case 2: // Q1 case 3: // Q2 case 4: // Q3 case 5: // Q4 cpType = "quarterly"; duration = 91; offset = (catalogInterval - 2) * duration; break; default: cpType = "monthly"; duration = 30; offset = (catalogInterval - 6) * duration; } long cpStartDateId = JULIAN_DATA_START_DATE + offset + ((cpCatalogNumber - 1) / CATALOGS_PER_YEAR) * 365; long cpEndDateId = cpStartDateId + duration - 1; String cpDescription = generateRandomText(WIDTH_CP_DESCRIPTION / 2, WIDTH_CP_DESCRIPTION - 1, getRandomNumberStream(CP_DESCRIPTION)); return new RowGeneratorResult(new CatalogPageRow( cpCatalogPageSk, cpCatalogPageId, cpStartDateId, cpEndDateId, cpDepartment, cpCatalogNumber, cpCatalogPageNumber, cpDescription, cpType, nullBitMap)); }
Example #27
Source File: PromotionRowGenerator.java From tpcds with Apache License 2.0 | 4 votes |
@Override public RowGeneratorResult generateRowAndChildRows(long rowNumber, Session session, RowGenerator parentRowGenerator, RowGenerator childRowGenerator) { long nullBitMap = createNullBitMap(PROMOTION, getRandomNumberStream(P_NULLS)); long pPromoSk = rowNumber; String pPromoId = makeBusinessKey(rowNumber); long pStartDateId = JULIAN_DATE_MINIMUM + generateUniformRandomInt(PROMO_START_MIN, PROMO_START_MAX, getRandomNumberStream(P_START_DATE_ID)); long pEndDateId = pStartDateId + generateUniformRandomInt(PROMO_LENGTH_MIN, PROMO_LENGTH_MAX, getRandomNumberStream(P_END_DATE_ID)); long pItemSk = generateJoinKey(P_ITEM_SK, getRandomNumberStream(P_ITEM_SK), Table.ITEM, 1, session.getScaling()); Decimal pCost = new Decimal(100000, 2); int pResponseTarget = 1; String pPromoName = generateWord(rowNumber, PROMO_NAME_LENGTH, SYLLABLES_DISTRIBUTION); int flags = generateUniformRandomInt(0, 511, getRandomNumberStream(P_CHANNEL_DMAIL)); boolean pChannelDmail = (flags & 0x01) != 0; flags <<= 1; boolean pChannelEmail = (flags & 0x01) != 0; flags <<= 1; boolean pChannelCatalog = (flags & 0x01) != 0; flags <<= 1; boolean pChannelTv = (flags & 0x01) != 0; flags <<= 1; boolean pChannelRadio = (flags & 0x01) != 0; flags <<= 1; boolean pChannelPress = (flags & 0x01) != 0; flags <<= 1; boolean pChannelEvent = (flags & 0x01) != 0; flags <<= 1; boolean pChannelDemo = (flags & 0x01) != 0; flags <<= 1; boolean pDiscountActive = (flags & 0x01) != 0; String pChannelDetails = generateRandomText(PROMO_DETAIL_LENGTH_MIN, PROMO_DETAIL_LENGTH_MAX, getRandomNumberStream(P_CHANNEL_DETAILS)); String pPurpose = "Unknown"; return new RowGeneratorResult(new PromotionRow(nullBitMap, pPromoSk, pPromoId, pStartDateId, pEndDateId, pItemSk, pCost, pResponseTarget, pPromoName, pChannelDmail, pChannelEmail, pChannelCatalog, pChannelTv, pChannelRadio, pChannelPress, pChannelEvent, pChannelDemo, pChannelDetails, pPurpose, pDiscountActive)); }
Example #28
Source File: DateDimRowGenerator.java From tpcds with Apache License 2.0 | 4 votes |
@Override public RowGeneratorResult generateRowAndChildRows(long rowNumber, Session session, RowGenerator parentRowGenerator, RowGenerator childRowGenerator) { long nullBitMap = createNullBitMap(DATE_DIM, getRandomNumberStream(D_NULLS)); Date baseDate = new Date(1900, 1, 1); long dDateSk = rowNumber + toJulianDays(baseDate); String dDateId = makeBusinessKey(dDateSk); Date date = fromJulianDays((int) dDateSk); int dYear = date.getYear(); int dDow = computeDayOfWeek(date); int dMoy = date.getMonth(); int dDom = date.getDay(); // set the sequence counts; assumes that the date table starts on a year boundary int dWeekSeq = ((int) rowNumber + 6) / 7; int dMonthSeq = (dYear - 1900) * 12 + dMoy - 1; int dQuarterSeq = (dYear - 1900) * 4 + dMoy / 3 + 1; int dayIndex = getDayIndex(date); int dQoy = getQuarterAtIndex(dayIndex); // fiscal year is identical to calendar year int dFyYear = dYear; int dFyQuarterSeq = dQuarterSeq; int dFyWeekSeq = dWeekSeq; String dDayName = WEEKDAY_NAMES[dDow]; boolean dHoliday = getIsHolidayFlagAtIndex(dayIndex) != 0; boolean dWeekend = dDow == 5 || dDow == 6; boolean dFollowingHoliday; if (dayIndex == 1) { // This is not correct-- the last day of the previous year is always the 366th day. // Copying behavior of C code. int lastDayOfPreviousYear = 365 + (isLeapYear(dYear - 1) ? 1 : 0); dFollowingHoliday = getIsHolidayFlagAtIndex(lastDayOfPreviousYear) != 0; } else { dFollowingHoliday = getIsHolidayFlagAtIndex(dayIndex - 1) != 0; } int dFirstDom = toJulianDays(computeFirstDateOfMonth(date)); int dLastDom = toJulianDays(computeLastDateOfMonth(date)); int dSameDayLy = toJulianDays(computeSameDayLastYear(date)); int dSameDayLq = toJulianDays(computeSameDayLastQuarter(date)); boolean dCurrentDay = dDateSk == TODAYS_DATE.getDay(); boolean dCurrentYear = dYear == TODAYS_DATE.getYear(); boolean dCurrentMonth = dCurrentYear && dMoy == TODAYS_DATE.getMonth(); boolean dCurrentQuarter = dCurrentYear && dQoy == CURRENT_QUARTER; boolean dCurrentWeek = dCurrentYear && dWeekSeq == CURRENT_WEEK; return new RowGeneratorResult(new DateDimRow(nullBitMap, dDateSk, dDateId, dMonthSeq, dWeekSeq, dQuarterSeq, dYear, dDow, dMoy, dDom, dQoy, dFyYear, dFyQuarterSeq, dFyWeekSeq, dDayName, dHoliday, dWeekend, dFollowingHoliday, dFirstDom, dLastDom, dSameDayLy, dSameDayLq, dCurrentDay, dCurrentWeek, dCurrentMonth, dCurrentQuarter, dCurrentYear)); }
Example #29
Source File: RowGenerator.java From tpcds with Apache License 2.0 | votes |
RowGeneratorResult generateRowAndChildRows(long rowNumber, Session session, RowGenerator parentRowGenerator, RowGenerator childRowGenerator);