Search in sources :

Example 6 with TextStringBuilder

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;
}
Also used : DataPage(org.apache.parquet.column.page.DataPage) ParquetFileReader(org.apache.parquet.hadoop.ParquetFileReader) ColumnDescriptor(org.apache.parquet.column.ColumnDescriptor) PageReader(org.apache.parquet.column.page.PageReader) Util.minMaxAsString(org.apache.parquet.cli.Util.minMaxAsString) Util.encodingAsString(org.apache.parquet.cli.Util.encodingAsString) TextStringBuilder(org.apache.commons.text.TextStringBuilder) CompressionCodecName(org.apache.parquet.hadoop.metadata.CompressionCodecName) PageReadStore(org.apache.parquet.column.page.PageReadStore) PrimitiveType(org.apache.parquet.schema.PrimitiveType) List(java.util.List) MessageType(org.apache.parquet.schema.MessageType) DictionaryPage(org.apache.parquet.column.page.DictionaryPage)

Example 7 with TextStringBuilder

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);
    }
}
Also used : Function(com.google.common.base.Function) ColumnChunkMetaData(org.apache.parquet.hadoop.metadata.ColumnChunkMetaData) Util.minMaxAsString(org.apache.parquet.cli.Util.minMaxAsString) Util.encodingsAsString(org.apache.parquet.cli.Util.encodingsAsString) Util.encodingStatsAsString(org.apache.parquet.cli.Util.encodingStatsAsString) TextStringBuilder(org.apache.commons.text.TextStringBuilder) Nullable(javax.annotation.Nullable)

Example 8 with TextStringBuilder

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());
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TextStringBuilder(org.apache.commons.text.TextStringBuilder)

Example 9 with TextStringBuilder

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");
}
Also used : TextStringBuilder(org.apache.commons.text.TextStringBuilder) Test(org.junit.jupiter.api.Test)

Example 10 with TextStringBuilder

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);
}
Also used : TextStringBuilder(org.apache.commons.text.TextStringBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

TextStringBuilder (org.apache.commons.text.TextStringBuilder)37 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Issue (org.apache.gobblin.runtime.troubleshooter.Issue)4 QueryStatement (com.djrapitops.plan.storage.database.queries.QueryStatement)3 Nullable (javax.annotation.Nullable)3 StringTokenizer (org.apache.commons.text.StringTokenizer)3 Test (org.junit.jupiter.api.Test)3 ServerUUID (com.djrapitops.plan.identification.ServerUUID)2 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)2 SecurityJpqlGenerator (com.haulmont.cuba.core.global.filter.SecurityJpqlGenerator)2 ConditionsTree (com.haulmont.cuba.gui.components.filter.ConditionsTree)2 FakeFilterSupport (com.haulmont.cuba.gui.components.filter.FakeFilterSupport)2 FilterParser (com.haulmont.cuba.gui.components.filter.FilterParser)2 FilterEditor (com.haulmont.cuba.gui.components.filter.edit.FilterEditor)2 FilterEntity (com.haulmont.cuba.security.entity.FilterEntity)2 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)2 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)2