Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions src/main/java/io/trino/tpch/Customer.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package io.trino.tpch;

import static io.trino.tpch.GenerateUtils.formatMoney;
import static java.util.Locale.ENGLISH;
import static io.trino.tpch.StringUtils.buildLine;
import static java.util.Objects.requireNonNull;

public class Customer
Expand Down Expand Up @@ -97,15 +97,6 @@ public String getComment()
@Override
public String toLine()
{
return String.format(ENGLISH,
"%d|%s|%s|%d|%s|%s|%s|%s|",
customerKey,
name,
address,
nationKey,
phone,
formatMoney(accountBalance),
marketSegment,
comment);
return buildLine(customerKey, name, address, nationKey, phone, formatMoney(accountBalance), marketSegment, comment);
}
}
5 changes: 2 additions & 3 deletions src/main/java/io/trino/tpch/LineItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import static io.trino.tpch.GenerateUtils.formatDate;
import static io.trino.tpch.GenerateUtils.formatMoney;
import static java.util.Locale.ENGLISH;
import static io.trino.tpch.StringUtils.buildLine;
import static java.util.Objects.requireNonNull;

public class LineItem
Expand Down Expand Up @@ -180,8 +180,7 @@ public String getComment()
@Override
public String toLine()
{
return String.format(ENGLISH,
"%d|%d|%d|%d|%d|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|",
return buildLine(
orderKey,
partKey,
supplierKey,
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/trino/tpch/Nation.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
package io.trino.tpch;

import static java.util.Locale.ENGLISH;
import static io.trino.tpch.StringUtils.buildLine;
import static java.util.Objects.requireNonNull;

public class Nation
Expand Down Expand Up @@ -63,6 +63,6 @@ public String getComment()
@Override
public String toLine()
{
return String.format(ENGLISH, "%d|%s|%d|%s|", nationKey, name, regionKey, comment);
return buildLine(nationKey, name, regionKey, comment);
}
}
5 changes: 2 additions & 3 deletions src/main/java/io/trino/tpch/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import static io.trino.tpch.GenerateUtils.formatDate;
import static io.trino.tpch.GenerateUtils.formatMoney;
import static java.util.Locale.ENGLISH;
import static io.trino.tpch.StringUtils.buildLine;
import static java.util.Objects.requireNonNull;

public class Order
Expand Down Expand Up @@ -114,8 +114,7 @@ public String getComment()
@Override
public String toLine()
{
return String.format(ENGLISH,
"%d|%d|%s|%s|%s|%s|%s|%d|%s|",
return buildLine(
orderKey,
customerKey,
orderStatus,
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/trino/tpch/OrderGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Iterator;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.padStart;
import static io.trino.tpch.GenerateUtils.MIN_GENERATE_DATE;
import static io.trino.tpch.GenerateUtils.TOTAL_DATE_RANGE;
import static io.trino.tpch.GenerateUtils.calculateRowCount;
Expand All @@ -30,7 +31,6 @@
import static io.trino.tpch.LineItemGenerator.createShipDateRandom;
import static io.trino.tpch.LineItemGenerator.createTaxRandom;
import static io.trino.tpch.PartGenerator.calculatePartPrice;
import static java.util.Locale.ENGLISH;
import static java.util.Objects.requireNonNull;

public class OrderGenerator
Expand Down Expand Up @@ -226,7 +226,7 @@ else if (shippedCount > 0) {
totalPrice,
toEpochDate(orderDate),
orderPriorityRandom.nextValue(),
String.format(ENGLISH, "Clerk#%09d", clerkRandom.nextValue()),
"Clerk#" + padStart(Integer.toString(clerkRandom.nextValue()), 9, '0'),
0,
commentRandom.nextValue());
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/io/trino/tpch/Part.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package io.trino.tpch;

import static io.trino.tpch.GenerateUtils.formatMoney;
import static java.util.Locale.ENGLISH;
import static io.trino.tpch.StringUtils.buildLine;
import static java.util.Objects.requireNonNull;

public class Part
Expand Down Expand Up @@ -113,9 +113,7 @@ public String getComment()
@Override
public String toLine()
{
return String.format(ENGLISH,
"%d|%s|%s|%s|%s|%d|%s|%s|%s|",
partKey,
return buildLine(partKey,
name,
manufacturer,
brand,
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/io/trino/tpch/PartGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static com.google.common.base.Preconditions.checkArgument;
import static io.trino.tpch.GenerateUtils.calculateRowCount;
import static io.trino.tpch.GenerateUtils.calculateStartIndex;
import static java.util.Locale.ENGLISH;
import static java.util.Objects.requireNonNull;

public class PartGenerator
Expand Down Expand Up @@ -143,8 +142,8 @@ private Part makePart(long partKey)
return new Part(partKey,
partKey,
name,
String.format(ENGLISH, "Manufacturer#%d", manufacturer),
String.format(ENGLISH, "Brand#%d", brand),
"Manufacturer#" + manufacturer,
"Brand#" + brand,
typeRandom.nextValue(),
sizeRandom.nextValue(),
containerRandom.nextValue(),
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/io/trino/tpch/PartSupplier.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package io.trino.tpch;

import static io.trino.tpch.GenerateUtils.formatMoney;
import static java.util.Locale.ENGLISH;
import static io.trino.tpch.StringUtils.buildLine;
import static java.util.Objects.requireNonNull;

public class PartSupplier
Expand Down Expand Up @@ -76,12 +76,6 @@ public String getComment()
@Override
public String toLine()
{
return String.format(ENGLISH,
"%d|%d|%d|%s|%s|",
partKey,
supplierKey,
availableQuantity,
formatMoney(supplyCost),
comment);
return buildLine(partKey, supplierKey, availableQuantity, formatMoney(supplyCost), comment);
}
}
12 changes: 5 additions & 7 deletions src/main/java/io/trino/tpch/RandomPhoneNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
package io.trino.tpch;

import static java.util.Locale.ENGLISH;
import static io.trino.tpch.StringUtils.padWithZeros;

public class RandomPhoneNumber
extends AbstractRandomInt
Expand All @@ -33,11 +33,9 @@ public RandomPhoneNumber(long seed, int expectedRowCount)

public String nextValue(long nationKey)
{
return String.format(ENGLISH,
"%02d-%03d-%03d-%04d",
(10 + (nationKey % NATIONS_MAX)),
nextInt(100, 999),
nextInt(100, 999),
nextInt(1000, 9999));
return padWithZeros(10 + (nationKey % NATIONS_MAX), 2) + '-' +
padWithZeros(nextInt(100, 999), 3) + '-' +
padWithZeros(nextInt(100, 999), 3) + '-' +
padWithZeros(nextInt(1000, 9999), 4);
}
}
4 changes: 2 additions & 2 deletions src/main/java/io/trino/tpch/Region.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
package io.trino.tpch;

import static java.util.Locale.ENGLISH;
import static io.trino.tpch.StringUtils.buildLine;
import static java.util.Objects.requireNonNull;

public class Region
Expand Down Expand Up @@ -56,6 +56,6 @@ public String getComment()
@Override
public String toLine()
{
return String.format(ENGLISH, "%d|%s|%s|", regionKey, name, comment);
return buildLine(regionKey, name, comment);
}
}
35 changes: 35 additions & 0 deletions src/main/java/io/trino/tpch/StringUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.tpch;

import com.google.common.base.Joiner;

import static com.google.common.base.Strings.padStart;

public class StringUtils
{
private static final Joiner LINE_JOINER = Joiner.on('|');

private StringUtils() {}

public static String padWithZeros(long value, int length)
{
return padStart(Long.toString(value), length, '0');
}

public static String buildLine(Object... values)
{
return LINE_JOINER.join(values) + "|";
}
}
5 changes: 2 additions & 3 deletions src/main/java/io/trino/tpch/Supplier.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package io.trino.tpch;

import static io.trino.tpch.GenerateUtils.formatMoney;
import static java.util.Locale.ENGLISH;
import static io.trino.tpch.StringUtils.buildLine;
import static java.util.Objects.requireNonNull;

public class Supplier
Expand Down Expand Up @@ -90,8 +90,7 @@ public String getComment()
@Override
public String toLine()
{
return String.format(ENGLISH,
"%d|%s|%s|%d|%s|%s|%s|",
return buildLine(
supplierKey,
name,
address,
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/trino/tpch/SupplierGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import static com.google.common.base.Preconditions.checkArgument;
import static io.trino.tpch.GenerateUtils.calculateRowCount;
import static io.trino.tpch.GenerateUtils.calculateStartIndex;
import static java.util.Locale.ENGLISH;
import static io.trino.tpch.StringUtils.padWithZeros;
import static java.util.Objects.requireNonNull;

public class SupplierGenerator
Expand Down Expand Up @@ -175,7 +175,7 @@ private Supplier makeSupplier(long supplierKey)

return new Supplier(supplierKey,
supplierKey,
String.format(ENGLISH, "Supplier#%09d", supplierKey),
"Supplier#" + padWithZeros(supplierKey, 9),
addressRandom.nextValue(),
nationKey,
phoneRandom.nextValue(nationKey),
Expand Down