Skip to content
Closed
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
75 changes: 75 additions & 0 deletions src/main/java/io/trino/tpch/HudiNation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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 static java.util.Locale.ENGLISH;
import static java.util.Objects.requireNonNull;

public class HudiNation
implements TpchEntity
{
private final long rowNumber;
private final long nationKey;
private final String name;
private final long regionKey;
private final String comment;
private final String hoodieCommitTime;

public HudiNation(long rowNumber, long nationKey, String name, long regionKey, String comment, String hoodieCommitTime)
{
this.rowNumber = rowNumber;
this.nationKey = nationKey;
this.name = requireNonNull(name, "name is null");
this.regionKey = regionKey;
this.comment = requireNonNull(comment, "comment is null");
this.hoodieCommitTime = requireNonNull(hoodieCommitTime, "hoodieCommitTime is null");
}

@Override
public long getRowNumber()
{
return rowNumber;
}

public long getNationKey()
{
return nationKey;
}

public String getName()
{
return name;
}

public long getRegionKey()
{
return regionKey;
}

public String getComment()
{
return comment;
}

public String getHoodieCommitTime()
{
return hoodieCommitTime;
}

@Override
public String toLine()
{
return String.format(ENGLISH, "%d|%s|%d|%s|%s|", nationKey, name, regionKey, comment, hoodieCommitTime);
}
}
112 changes: 112 additions & 0 deletions src/main/java/io/trino/tpch/HudiNationColumn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* 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 static io.trino.tpch.TpchColumnTypes.IDENTIFIER;
import static io.trino.tpch.TpchColumnTypes.varchar;

public enum HudiNationColumn
implements TpchColumn<HudiNation>
{
NATION_KEY("n_nationkey", IDENTIFIER) {
@Override
public long getIdentifier(HudiNation nation)
{
return nation.getNationKey();
}
},

NAME("n_name", varchar(25)) {
@Override
public String getString(HudiNation nation)
{
return nation.getName();
}
},

REGION_KEY("n_regionkey", IDENTIFIER) {
@Override
public long getIdentifier(HudiNation nation)
{
return nation.getRegionKey();
}
},

COMMENT("n_comment", varchar(152)) {
@Override
public String getString(HudiNation nation)
{
return nation.getComment();
}
},

_HUDI_NATION_COLUMN("n__hoodie_commit_time", varchar(17)){
@Override
public String getString(HudiNation nation)
{
return nation.getHoodieCommitTime();
}
};

private final String columnName;
private final TpchColumnType type;

HudiNationColumn(String columnName, TpchColumnType type)
{
this.columnName = columnName;
this.type = type;
}

@Override
public String getColumnName()
{
return columnName;
}

@Override
public TpchColumnType getType()
{
return type;
}

@Override
public double getDouble(HudiNation nation)
{
throw new UnsupportedOperationException();
}

@Override
public long getIdentifier(HudiNation nation)
{
throw new UnsupportedOperationException();
}

@Override
public int getInteger(HudiNation nation)
{
throw new UnsupportedOperationException();
}

@Override
public String getString(HudiNation nation)
{
throw new UnsupportedOperationException();
}

@Override
public int getDate(HudiNation entity)
{
throw new UnsupportedOperationException();
}
}
89 changes: 89 additions & 0 deletions src/main/java/io/trino/tpch/HudiNationGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* 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.collect.AbstractIterator;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;

import static java.util.Objects.requireNonNull;

public class HudiNationGenerator
implements Iterable<HudiNation>
{
private static final int COMMENT_AVERAGE_LENGTH = 72;

private final Distributions distributions;
private final TextPool textPool;
private static final String HOODIE_INSTANT_TIME_FORMAT = "yyyyMMddHHmmssSSS";

public HudiNationGenerator()
{
this(Distributions.getDefaultDistributions(), TextPool.getDefaultTestPool());
}

public HudiNationGenerator(Distributions distributions, TextPool textPool)
{
this.distributions = requireNonNull(distributions, "distributions is null");
this.textPool = requireNonNull(textPool, "textPool is null");
}

@Override
public Iterator<HudiNation> iterator()
{
SimpleDateFormat instantTimeFormat = new SimpleDateFormat(HOODIE_INSTANT_TIME_FORMAT);
Date timestamp = new Date();
String hoodieInstantTime = instantTimeFormat.format(timestamp);
return new HudiNationGeneratorIterator(distributions.getNations(), textPool, hoodieInstantTime);
}

private static class HudiNationGeneratorIterator
extends AbstractIterator<HudiNation>
{
private final Distribution nations;
private final RandomText commentRandom;

private final String hoodieInstantTime;

private int index;

private HudiNationGeneratorIterator(Distribution nations, TextPool textPool, String hoodieInstantTime)
{
this.nations = nations;
this.commentRandom = new RandomText(606179079, textPool, COMMENT_AVERAGE_LENGTH);
this.hoodieInstantTime = hoodieInstantTime;
}

@Override
protected HudiNation computeNext()
{
if (index >= nations.size()) {
return endOfData();
}
HudiNation nation = new HudiNation(index,
index,
nations.getValue(index),
nations.getWeight(index),
commentRandom.nextValue(),
hoodieInstantTime);

commentRandom.rowFinished();
index++;

return nation;
}
}
}
14 changes: 13 additions & 1 deletion src/main/java/io/trino/tpch/TpchTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ public Iterable<Nation> createGenerator(double scaleFactor, int part, int partCo
}
};

public static final TpchTable<HudiNation> HUDINATION = new TpchTable<HudiNation>("hoodie_nation", HudiNationColumn.values())
{
@Override
public Iterable<HudiNation> createGenerator(double scaleFactor, int part, int partCount)
{
if (part != 1) {
return ImmutableList.of();
}
return new HudiNationGenerator();
}
};

public static final TpchTable<Region> REGION = new TpchTable<Region>("region", RegionColumn.values())
{
@Override
Expand All @@ -105,7 +117,7 @@ public Iterable<Region> createGenerator(double scaleFactor, int part, int partCo
private static final Map<String, TpchTable<?>> TABLES_BY_NAME;

static {
TABLES = ImmutableList.of(CUSTOMER, ORDERS, LINE_ITEM, PART, PART_SUPPLIER, SUPPLIER, NATION, REGION);
TABLES = ImmutableList.of(CUSTOMER, ORDERS, LINE_ITEM, PART, PART_SUPPLIER, SUPPLIER, NATION, REGION, HUDINATION);
TABLES_BY_NAME = Maps.uniqueIndex(TABLES, TpchTable::getTableName);
}

Expand Down