This is an automated email from the ASF dual-hosted git repository.
gabor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/parquet-mr.git
The following commit(s) were added to refs/heads/master by this push:
new ab65823 [PARQUET-1808]: Replacing multiple String Object creations
with StringBuilder (#766)
ab65823 is described below
commit ab65823ae0fd6c3afae94c7fa0670cf9b46b5b85
Author: Shankar Koirala <[email protected]>
AuthorDate: Mon Mar 9 12:52:39 2020 +0100
[PARQUET-1808]: Replacing multiple String Object creations with
StringBuilder (#766)
---
.../parquet/example/data/simple/SimpleGroup.java | 38 ++++++++++++----------
.../org/apache/parquet/io/MessageColumnIO.java | 12 +++----
.../parquet/io/ExpectationValidatingConverter.java | 14 ++++----
.../org/apache/parquet/hadoop/TestInputFormat.java | 14 ++++----
4 files changed, 41 insertions(+), 37 deletions(-)
diff --git
a/parquet-column/src/main/java/org/apache/parquet/example/data/simple/SimpleGroup.java
b/parquet-column/src/main/java/org/apache/parquet/example/data/simple/SimpleGroup.java
index 1bfe8d3..3caab9e 100644
---
a/parquet-column/src/main/java/org/apache/parquet/example/data/simple/SimpleGroup.java
+++
b/parquet-column/src/main/java/org/apache/parquet/example/data/simple/SimpleGroup.java
@@ -1,4 +1,4 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -6,9 +6,9 @@
* to you 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
@@ -47,29 +47,33 @@ public class SimpleGroup extends Group {
return toString("");
}
- public String toString(String indent) {
- String result = "";
+ private StringBuilder appendToString(StringBuilder builder, String indent) {
int i = 0;
for (Type field : schema.getFields()) {
String name = field.getName();
List<Object> values = data[i];
++i;
- if (values != null) {
- if (values.size() > 0) {
- for (Object value : values) {
- result += indent + name;
- if (value == null) {
- result += ": NULL\n";
- } else if (value instanceof Group) {
- result += "\n" + ((SimpleGroup)value).toString(indent+" ");
- } else {
- result += ": " + value.toString() + "\n";
- }
+ if (values != null && !values.isEmpty()) {
+ for (Object value : values) {
+ builder.append(indent).append(name);
+ if (value == null) {
+ builder.append(": NULL\n");
+ } else if (value instanceof Group) {
+ builder.append('\n');
+ ((SimpleGroup) value).appendToString(builder, indent + " ");
+ } else {
+ builder.append(": ").append(value.toString()).append('\n');
}
}
}
}
- return result;
+ return builder;
+ }
+
+ public String toString(String indent) {
+ StringBuilder builder = new StringBuilder();
+ appendToString(builder, indent);
+ return builder.toString();
}
@Override
diff --git
a/parquet-column/src/main/java/org/apache/parquet/io/MessageColumnIO.java
b/parquet-column/src/main/java/org/apache/parquet/io/MessageColumnIO.java
index bad39ff..0496c51 100644
--- a/parquet-column/src/main/java/org/apache/parquet/io/MessageColumnIO.java
+++ b/parquet-column/src/main/java/org/apache/parquet/io/MessageColumnIO.java
@@ -1,4 +1,4 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -6,9 +6,9 @@
* to you 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
@@ -276,11 +276,11 @@ public class MessageColumnIO extends GroupColumnIO {
private void log(Object message, Object...parameters) {
if (DEBUG) {
- String indent = "";
+ StringBuilder indent = new StringBuilder(currentLevel * 2);
for (int i = 0; i < currentLevel; ++i) {
- indent += " ";
+ indent.append(" ");
}
- LOG.debug(indent + message, parameters);
+ LOG.debug(indent.toString() + message, parameters);
}
}
diff --git
a/parquet-column/src/test/java/org/apache/parquet/io/ExpectationValidatingConverter.java
b/parquet-column/src/test/java/org/apache/parquet/io/ExpectationValidatingConverter.java
index e99da98..3e47315 100644
---
a/parquet-column/src/test/java/org/apache/parquet/io/ExpectationValidatingConverter.java
+++
b/parquet-column/src/test/java/org/apache/parquet/io/ExpectationValidatingConverter.java
@@ -1,4 +1,4 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -6,9 +6,9 @@
* to you 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
@@ -151,14 +151,14 @@ public class ExpectationValidatingConverter extends
RecordMaterializer<Void> {
}
private String path(List<GroupType> path, Type type) {
- String pathString = "";
+ StringBuilder pathString = new StringBuilder();
if (path.size() > 0) {
for (int i = 1; i < path.size(); i++) {
- pathString += path.get(i).getName() + ".";
+ pathString.append(path.get(i).getName()).append('.');
}
}
- pathString += type.getName() + ".";
- return pathString;
+ pathString.append(type.getName()).append('.');
+ return pathString.toString();
}
@Override
diff --git
a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInputFormat.java
b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInputFormat.java
index d8b3de3..d950316 100644
---
a/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInputFormat.java
+++
b/parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInputFormat.java
@@ -1,4 +1,4 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -6,9 +6,9 @@
* to you 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
@@ -391,18 +391,18 @@ public class TestInputFormat {
tempDir.deleteOnExit();
int numFiles = 10; // create a nontrivial number of files so that it
actually tests getFooters() returns files in the correct order
- String url = "";
+ StringBuilder url = new StringBuilder();
for (int i = 0; i < numFiles; i++) {
File file = new File(tempDir, String.format("part-%05d.parquet", i));
createParquetFile(file);
if (i > 0) {
- url += ",";
+ url.append(',');
}
- url += "file:" + file.getAbsolutePath();
+ url.append("file:").append(file.getAbsolutePath());
}
Job job = new Job();
- FileInputFormat.setInputPaths(job, url);
+ FileInputFormat.setInputPaths(job, url.toString());
List<Footer> footers = new ParquetInputFormat<Object>().getFooters(job);
for (int i = 0; i < numFiles; i++) {
Footer footer = footers.get(i);