use of org.apache.commons.text.TextStringBuilder in project parquet-mr by apache.
the class ShowPagesCommand method run.
@Override
@SuppressWarnings("unchecked")
public int run() throws IOException {
Preconditions.checkArgument(targets != null && targets.size() >= 1, "A Parquet file is required.");
Preconditions.checkArgument(targets.size() == 1, "Cannot process multiple Parquet files.");
String source = targets.get(0);
try (ParquetFileReader reader = ParquetFileReader.open(getConf(), qualifiedPath(source))) {
MessageType schema = reader.getFileMetaData().getSchema();
Map<ColumnDescriptor, PrimitiveType> columns = Maps.newLinkedHashMap();
if (this.columns == null || this.columns.isEmpty()) {
for (ColumnDescriptor descriptor : schema.getColumns()) {
columns.put(descriptor, primitive(schema, descriptor.getPath()));
}
} else {
for (String column : this.columns) {
columns.put(descriptor(column, schema), primitive(column, schema));
}
}
CompressionCodecName codec = reader.getRowGroups().get(0).getColumns().get(0).getCodec();
// accumulate formatted lines to print by column
Map<String, List<String>> formatted = Maps.newLinkedHashMap();
PageFormatter formatter = new PageFormatter();
PageReadStore pageStore;
int rowGroupNum = 0;
while ((pageStore = reader.readNextRowGroup()) != null) {
for (ColumnDescriptor descriptor : columns.keySet()) {
List<String> lines = formatted.get(columnName(descriptor));
if (lines == null) {
lines = Lists.newArrayList();
formatted.put(columnName(descriptor), lines);
}
formatter.setContext(rowGroupNum, columns.get(descriptor), codec);
PageReader pages = pageStore.getPageReader(descriptor);
DictionaryPage dict = pages.readDictionaryPage();
if (dict != null) {
lines.add(formatter.format(dict));
}
DataPage page;
while ((page = pages.readPage()) != null) {
lines.add(formatter.format(page));
}
}
rowGroupNum += 1;
}
// TODO: Show total column size and overall size per value in the column summary line
for (String columnName : formatted.keySet()) {
console.info(String.format("\nColumn: %s\n%s", columnName, new TextStringBuilder(80).appendPadding(80, '-')));
console.info(formatter.getHeader());
for (String line : formatted.get(columnName)) {
console.info(line);
}
console.info("");
}
}
return 0;
}
use of org.apache.commons.text.TextStringBuilder in project parquet-mr by apache.
the class ParquetMetadataCommand method printRowGroup.
private void printRowGroup(Logger console, int index, BlockMetaData rowGroup, MessageType schema) {
long start = rowGroup.getStartingPos();
long rowCount = rowGroup.getRowCount();
long compressedSize = rowGroup.getCompressedSize();
long uncompressedSize = rowGroup.getTotalByteSize();
String filePath = rowGroup.getPath();
console.info(String.format("\nRow group %d: count: %d %s records start: %d total(compressed): %s total(uncompressed):%s %s\n%s", index, rowCount, humanReadable(((float) compressedSize) / rowCount), start, humanReadable(compressedSize), humanReadable(uncompressedSize), filePath != null ? "path: " + filePath : "", new TextStringBuilder(80).appendPadding(80, '-')));
int size = maxSize(Iterables.transform(rowGroup.getColumns(), new Function<ColumnChunkMetaData, String>() {
@Override
public String apply(@Nullable ColumnChunkMetaData input) {
return input == null ? "" : input.getPath().toDotString();
}
}));
console.info(String.format("%-" + size + "s %-9s %-9s %-9s %-10s %-7s %s", "", "type", "encodings", "count", "avg size", "nulls", "min / max"));
for (ColumnChunkMetaData column : rowGroup.getColumns()) {
printColumnChunk(console, size, column, schema);
}
}
use of org.apache.commons.text.TextStringBuilder in project quarkus-test-framework by quarkus-qe.
the class FileMetricsExporter method push.
@Override
public void push(String serviceName, Map<String, String> labels) throws IOException {
Map<String, Object> allMetrics = new HashMap<>();
allMetrics.putAll(labels);
allMetrics.putAll(metrics);
TextStringBuilder sw = new TextStringBuilder();
allMetrics.keySet().stream().sorted().forEach(metricId -> sw.appendln(String.format("%s=%s", metricId, allMetrics.get(metricId))));
Files.write(Path.of(METRICS_EXPORT_FILE_OUTPUT.get()), sw.toString().getBytes());
}
use of org.apache.commons.text.TextStringBuilder in project sda-dropwizard-commons by SDA-SE.
the class SystemPropertyAndEnvironmentSubstitutorTest method shouldReplaceProperty.
@Test
void shouldReplaceProperty() {
final String input = "this is a ${TEST}";
final TextStringBuilder builder = new TextStringBuilder(input);
boolean altered = new SystemPropertyAndEnvironmentSubstitutor(false).substitute(builder, 0, input.length());
assertThat(altered).isTrue();
assertThat(builder.build()).isEqualTo("this is a foobar");
}
use of org.apache.commons.text.TextStringBuilder in project sda-dropwizard-commons by SDA-SE.
the class SystemPropertyAndEnvironmentSubstitutorTest method shouldThrowExceptionIfStrict.
@Test
void shouldThrowExceptionIfStrict() {
final String input = "this is a ${UNKNOWN_PROPERTY}";
final TextStringBuilder builder = new TextStringBuilder(input);
final SystemPropertyAndEnvironmentSubstitutor substitutor = new SystemPropertyAndEnvironmentSubstitutor(true);
final int length = input.length();
assertThatCode(() -> substitutor.substitute(builder, 0, length)).isInstanceOf(UndefinedEnvironmentVariableException.class);
}
Aggregations