Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix the usage of pivot type with all pivot options #68

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ private void addTmpHeader(final BaseHeader header, final Set<String> pivotEntryT

if (header instanceof PivotKeyHeader) {
final var pivotHeader = (PivotKeyHeader) header.clone();

if (!pivotEntryTypes.isEmpty()) {
pivotHeader.setEntryTypeValues(pivotEntryTypes);
}

if (this.getSheet().getPivotOption() == PivotOption.WITH_TYPE_AND_VALUE) {
if (!pivotEntryTypes.isEmpty()) {
pivotHeader.setEntryTypeValues(pivotEntryTypes);
}
this.addHeaderIntoTmpHeaders(pivotHeader, false);
pivotHeader.getEntryTypeValues().forEach(
x -> this.addHeaderIntoTmpHeaders(pivotHeader.getPivotTypeHeader().clone().setName(x), false));
Expand Down Expand Up @@ -191,20 +193,23 @@ private List<Row> emitAllRowsForOneRow(final BaseTableGraph graph, final DataTab
}
if (pivotKeyHeader == null) {
this.emitOneRowWithoutPivot(graph, orgTable, orgRow, rowGroup).ifPresent(newRows::add);
} else if (this.getSheet().getPivotOption() == PivotOption.WITH_TYPE_AND_VALUE) {
pivotKeyHeader.getEntryPivotValues()
.forEach(x -> this
.emitOneRowWithPivotTypeAndValue(graph, orgTable, orgRow, rowGroup, pivotKeyHeader, x,
this.findTypeValue(orgTable, orgRow, pivotTypeHeader))
.ifPresent(newRows::add));
} else if (this.getSheet().getPivotOption() == PivotOption.WITH_TYPE) {
pivotKeyHeader.getEntries()
.forEach(x -> this.emitOneRowWithPivotAndType(graph, orgTable, orgRow, rowGroup, x)
.ifPresent(newRows::add));
} else {
pivotKeyHeader.getEntries()
.forEach(x -> this.emitOneRowWithPivot(graph, orgTable, orgRow, rowGroup, x)
.ifPresent(newRows::add));
final var typeValue = this.findTypeValue(orgTable, orgRow, pivotTypeHeader);
if (this.getSheet().getPivotOption() == PivotOption.WITH_TYPE_AND_VALUE) {
pivotKeyHeader.getEntryPivotValues()
.forEach(x -> this
.emitOneRowWithPivotTypeAndValue(graph, orgTable, orgRow, rowGroup, pivotKeyHeader, x,
typeValue)
.ifPresent(newRows::add));
} else if (this.getSheet().getPivotOption() == PivotOption.WITH_TYPE) {
pivotKeyHeader.getEntries()
.forEach(x -> this.emitOneRowWithPivotAndType(graph, orgTable, orgRow, rowGroup, x, typeValue)
.ifPresent(newRows::add));
} else {
pivotKeyHeader.getEntries()
.forEach(x -> this.emitOneRowWithPivot(graph, orgTable, orgRow, rowGroup, x, typeValue)
.ifPresent(newRows::add));
}
}
return newRows;
}
Expand Down Expand Up @@ -257,10 +262,13 @@ private Optional<Row> emitOneRowWithPivotTypeAndValue(final BaseTableGraph graph
}

private Optional<Row> emitOneRowWithPivotAndType(final BaseTableGraph graph, final DataTable orgTable,
final BaseRow orgRow, final RowGroup rowGroup, final PivotEntry pivotEntry) {
final BaseRow orgRow, final RowGroup rowGroup, final PivotEntry pivotEntry, final String typeValue) {
if (!orgRow.getCellAt(pivotEntry.getCell().getColumnIndex()).hasValue()) {
return Optional.empty();
}
if (typeValue != null && !typeValue.equals(pivotEntry.getTypeValue())) {
return Optional.empty();
}

final var newRow = new Row(this.tmpHeaders.size());
for (final var tmpHeader : this.tmpHeaders) {
Expand All @@ -283,10 +291,13 @@ private Optional<Row> emitOneRowWithPivotAndType(final BaseTableGraph graph, fin
}

private Optional<Row> emitOneRowWithPivot(final BaseTableGraph graph, final DataTable orgTable,
final BaseRow orgRow, final RowGroup rowGroup, final PivotEntry pivotEntry) {
final BaseRow orgRow, final RowGroup rowGroup, final PivotEntry pivotEntry, final String typeValue) {
if (!orgRow.getCellAt(pivotEntry.getCell().getColumnIndex()).hasValue()) {
return Optional.empty();
}
if (typeValue != null && !typeValue.equals(pivotEntry.getTypeValue())) {
return Optional.empty();
}

final var newRow = new Row(this.tmpHeaders.size());
for (final var tmpHeader : this.tmpHeaders) {
Expand Down
Loading