Java Code Examples for com.teradata.tpcds.Session#getScaling()

The following examples show how to use com.teradata.tpcds.Session#getScaling() . 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: InventoryRowGenerator.java    From tpcds with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: StoreSalesRowGenerator.java    From tpcds with Apache License 2.0 6 votes vote down vote up
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: WebSalesRowGenerator.java    From tpcds with Apache License 2.0 5 votes vote down vote up
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 4
Source File: CustomerRowGenerator.java    From tpcds with Apache License 2.0 4 votes vote down vote up
@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 5
Source File: StoreReturnsRowGenerator.java    From tpcds with Apache License 2.0 4 votes vote down vote up
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 6
Source File: WebSalesRowGenerator.java    From tpcds with Apache License 2.0 4 votes vote down vote up
@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 7
Source File: CatalogSalesRowGenerator.java    From tpcds with Apache License 2.0 4 votes vote down vote up
@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 8
Source File: CatalogSalesRowGenerator.java    From tpcds with Apache License 2.0 4 votes vote down vote up
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 9
Source File: WebReturnsRowGenerator.java    From tpcds with Apache License 2.0 4 votes vote down vote up
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 10
Source File: StoreSalesRowGenerator.java    From tpcds with Apache License 2.0 4 votes vote down vote up
@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 11
Source File: CatalogReturnsRowGenerator.java    From tpcds with Apache License 2.0 4 votes vote down vote up
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);
}