Skip to content

Commit

Permalink
Additional small performance improvements (apache#651)
Browse files Browse the repository at this point in the history
* Additional small performance improvements
  • Loading branch information
TheRealHaui authored and nichunen committed May 31, 2019
1 parent d533d18 commit 581299b
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public int compare(ReaderBuffer i, ReaderBuffer j) {

@Override
public boolean moveNext() throws IOException {
while (pq.size() > 0) {
while (!pq.isEmpty()) {
ReaderBuffer buffer = pq.poll();
String minEntry = buffer.pop();
this.colValue = minEntry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private void addValue(byte[] valueBytes) {
if (comp > 0) {
logger.info("values not in ascending order, previous '{}', current '{}'", previousValue, valueByteArray);
isOrdered = false;
if (trees.size() > 0) {
if (!trees.isEmpty()) {
throw new IllegalStateException("Invalid input data. Unordered data cannot be split into multi trees");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public byte[] firstValue() {
AppendDictNode p = this;
while (true) {
bytes.write(p.part, 0, p.part.length);
if (p.isEndOfValue || p.children.size() == 0) {
if (p.isEndOfValue || p.children.isEmpty()) {
break;
}
p = p.children.get(0);
Expand Down Expand Up @@ -381,4 +381,4 @@ public void visit(AppendDictNode n, int level) {
}, 0);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public boolean equals(Object o) {

void writeData(DataOutput out) throws IOException {
out.writeInt(rowIndices.size());
if (rowIndices.size() > 0) {
if (!rowIndices.isEmpty()) {
int n = rowIndices.get(0).length;
out.writeInt(n);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public int getStorageBytesEstimate() {
public void serialize(TopNCounter<ByteArray> value, ByteBuffer out) {
double[] counters = value.getCounters();
List<Counter<ByteArray>> peek = value.topK(1);
int keyLength = peek.size() > 0 ? peek.get(0).getItem().length() : 0;
int keyLength = !peek.isEmpty() ? peek.get(0).getItem().length() : 0;
out.putInt(value.getCapacity());
out.putInt(value.size());
out.putInt(keyLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void setCardinality(String cardinality) {

String[] cardi = cardinality.split(",");

if (0 == this.columnStats.size()) {
if (this.columnStats.isEmpty()) {
for (int i = 0; i < cardi.length; i++) {
ColumnStats columnStat = new ColumnStats();
columnStat.setCardinality(Long.parseLong(cardi[i]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,7 @@ private void attachSegmentMetadataWithDict(CubeSegment segment) throws IOExcepti
}

private void attachSegmentsMetadataWithDict(List<CubeSegment> segments) throws IOException {
Set<String> dumpList = new LinkedHashSet<>();
dumpList.addAll(JobRelatedMetaUtil.collectCubeMetadata(segments.get(0).getCubeInstance()));
Set<String> dumpList = new LinkedHashSet<>(JobRelatedMetaUtil.collectCubeMetadata(segments.get(0).getCubeInstance()));
ResourceStore rs = ResourceStore.getStore(segments.get(0).getConfig());
for (CubeSegment segment : segments) {
dumpList.addAll(segment.getDictionaryPaths());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected AvaticaResultSet execute() throws SQLException {
List<Object> paramValues = null;
if (!(statement instanceof KylinPreparedStatement)) {
params = null;
} else if (params != null && params.size() > 0) {
} else if (params != null && !params.isEmpty()) {
paramValues = ((KylinPreparedStatement) statement).getParameterJDBCValues();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private void validateInput(TableDesc tableDesc, StreamingSourceConfig streamingS
incompatibleMsgs.add(msg);
}
}
if (incompatibleMsgs.size() > 0) {
if (!incompatibleMsgs.isEmpty()) {
logger.info("incompatible for hive and input table schema:{}", incompatibleMsgs);
throw new BadRequestException("incompatible for hive schema and input table schema:" + incompatibleMsgs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void validateTable(String project, String table) throws IOException {
}

public void validateColumn(String project, String table, Collection<String> columns) throws IOException {
Preconditions.checkState(columns != null && columns.size() > 0);
Preconditions.checkState(columns != null && !columns.isEmpty());
Set<String> cols = getAllColumns(project, table);
for (String c : columns) {
if (!cols.contains(c)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ public String toString() {
builder.append(properties.toString());
}
builder.append(" ");
builder.append(duration + "ms");
builder.append(duration);
builder.append("ms");
return builder.toString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ public void copy(RawRecord another) {
if (another.getDimensions().length != dimensions.length || another.getMetrics().length != metrics.length) {
throw new IllegalStateException("cannot copy record with different schema");
}
for (int i = 0; i < another.dimensions.length; i++) {
this.dimensions[i] = another.dimensions[i];
}
for (int i = 0; i < another.metrics.length; i++) {
this.metrics[i] = another.metrics[i];
}
System.arraycopy(another.dimensions, 0, this.dimensions, 0, another.dimensions.length);
System.arraycopy(another.metrics, 0, this.metrics, 0, another.metrics.length);
}

public RawRecord clone() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ public void makeCubeSegmentImmutable(String cubeName, String segmentName) {
public void remoteSegmentBuildComplete(String cubeName, String segmentName) {
StreamingSegmentManager segmentManager = getStreamingSegmentManager(cubeName);
List<String> removedSegments = segmentManager.remoteSegmentBuildComplete(segmentName);
if (removedSegments.size() > 0) {
if (!removedSegments.isEmpty()) {
resumeConsumerIfPaused(cubeName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.kylin.stream.server.rest.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -106,9 +107,7 @@ public class QueryUtil {
static {
for (String q : tableauTestQueries) {
HashSet<String> temp = new HashSet<String>();
for (String token : q.split("[\r\n\t \\(\\)]")) {
temp.add(token);
}
Collections.addAll(temp, q.split("[\r\n\t \\(\\)]"));
temp.add("");
tableauTestQueriesInToken.add(temp);
}
Expand Down

0 comments on commit 581299b

Please sign in to comment.