Skip to content

Commit

Permalink
Enable check style plugin in pulsar sql module (apache#13781)
Browse files Browse the repository at this point in the history
Motivation
enable checkStyle plugin in pulsar-sql module.
  • Loading branch information
liudezhi2098 authored Jan 20, 2022
1 parent d9faf78 commit d42d30e
Show file tree
Hide file tree
Showing 25 changed files with 87 additions and 68 deletions.
19 changes: 19 additions & 0 deletions pulsar-sql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,23 @@
</dependencies>
</dependencyManagement>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<executions>
<execution>
<id>checkstyle</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static ClassLayout parseClass(Class<?> clazz) {
try {
size = ObjectSizeCalculator.getObjectSize(new ObjenesisStd().newInstance(clazz));
} catch (Throwable th) {
log.info("Error estimating size of class %s",clazz, th);
log.info("Error estimating size of class %s", clazz, th);
}
return new ClassLayout(Math.toIntExact(size));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* 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
* regarding copyright ownership. The ASF licenses this file
* 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
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Implementation of the connector to the Presto engine.
*/
package org.openjdk.jol.info;
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import io.prestosql.decoder.DecoderColumnHandle;
import io.prestosql.spi.connector.ColumnMetadata;
import io.prestosql.spi.type.Type;

import java.util.Objects;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import io.prestosql.spi.connector.ColumnMetadata;
import io.prestosql.spi.type.Type;

import java.util.Objects;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import io.prestosql.spi.type.Type;
import io.prestosql.spi.type.TypeId;
import io.prestosql.spi.type.TypeManager;

import javax.inject.Inject;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@
package org.apache.pulsar.sql.presto;

import static java.lang.String.format;

import com.google.inject.Inject;

import io.airlift.log.Logger;

import io.prestosql.decoder.DecoderColumnHandle;
import io.prestosql.spi.connector.ColumnMetadata;
import io.prestosql.spi.type.TypeManager;

import java.util.List;
import java.util.Set;

import org.apache.pulsar.common.naming.TopicName;
import org.apache.pulsar.common.schema.SchemaInfo;
import org.apache.pulsar.common.schema.SchemaType;
Expand Down Expand Up @@ -70,7 +65,7 @@ private PulsarRowDecoderFactory createDecoderFactory(SchemaInfo schemaInfo) {
return new PulsarAvroRowDecoderFactory(typeManager);
} else if (SchemaType.JSON.equals(schemaInfo.getType())) {
return new PulsarJsonRowDecoderFactory(typeManager);
}else if (SchemaType.PROTOBUF_NATIVE.equals(schemaInfo.getType())) {
} else if (SchemaType.PROTOBUF_NATIVE.equals(schemaInfo.getType())) {
return new PulsarProtobufNativeRowDecoderFactory(typeManager);
} else if (schemaInfo.getType().isPrimitive()) {
return new PulsarPrimitiveRowDecoderFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.isNullOrEmpty;
import static java.util.Objects.requireNonNull;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import io.prestosql.spi.type.BigintType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import static org.apache.pulsar.sql.presto.PulsarConnectorUtils.rewriteNamespaceDelimiterIfNeeded;
import static org.apache.pulsar.sql.presto.PulsarHandleResolver.convertColumnHandle;
import static org.apache.pulsar.sql.presto.PulsarHandleResolver.convertTableHandle;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static io.prestosql.decoder.FieldValueProviders.bytesValueProvider;
import static io.prestosql.decoder.FieldValueProviders.longValueProvider;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.annotations.VisibleForTesting;
Expand Down Expand Up @@ -364,8 +363,8 @@ class ReadEntries implements AsyncCallbacks.ReadEntriesCallback {
public void run() {

if (outstandingReadsRequests.get() > 0) {
if (!cursor.hasMoreEntries() ||
(((PositionImpl) cursor.getReadPosition()).compareTo(pulsarSplit.getEndPosition()) >= 0
if (!cursor.hasMoreEntries()
|| (((PositionImpl) cursor.getReadPosition()).compareTo(pulsarSplit.getEndPosition()) >= 0
&& chunkedMessagesMap.isEmpty())) {
isDone = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import io.prestosql.spi.connector.RecordCursor;
import io.prestosql.spi.connector.RecordSet;
import io.prestosql.spi.type.Type;

import java.util.List;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import io.netty.buffer.ByteBuf;
import io.prestosql.decoder.DecoderColumnHandle;
import io.prestosql.decoder.FieldValueProvider;

import java.util.Map;
import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@
package org.apache.pulsar.sql.presto;

import static java.util.concurrent.CompletableFuture.completedFuture;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

import org.apache.pulsar.client.admin.PulsarAdmin;
import org.apache.pulsar.client.admin.PulsarAdminException;
import org.apache.pulsar.client.api.Schema;
Expand All @@ -42,7 +39,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
* Multi version schema info provider for Pulsar SQL leverage guava cache.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import static java.lang.Float.floatToIntBits;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;

import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet;
import io.airlift.slice.Slice;
Expand Down Expand Up @@ -55,11 +54,9 @@
import io.prestosql.spi.type.VarbinaryType;
import io.prestosql.spi.type.VarcharType;
import java.nio.ByteBuffer;

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.avro.generic.GenericEnumSymbol;
import org.apache.avro.generic.GenericFixed;
import org.apache.avro.generic.GenericRecord;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@
import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static io.prestosql.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR;
import static java.util.Objects.requireNonNull;

import io.netty.buffer.ByteBuf;
import io.prestosql.decoder.DecoderColumnHandle;
import io.prestosql.decoder.FieldValueProvider;
import io.prestosql.spi.PrestoException;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import org.apache.avro.generic.GenericRecord;
import org.apache.pulsar.client.impl.schema.generic.GenericAvroRecord;
import org.apache.pulsar.client.impl.schema.generic.GenericAvroSchema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import static io.prestosql.spi.type.VarcharType.createUnboundedVarcharType;
import static java.lang.String.format;
import static java.util.stream.Collectors.toList;

import com.google.common.collect.ImmutableList;
import io.airlift.log.Logger;
import io.prestosql.decoder.DecoderColumnHandle;
Expand All @@ -46,11 +45,9 @@
import io.prestosql.spi.type.TypeSignatureParameter;
import io.prestosql.spi.type.VarbinaryType;
import io.prestosql.spi.type.VarcharType;

import java.util.List;
import java.util.Optional;
import java.util.Set;

import org.apache.avro.LogicalType;
import org.apache.avro.LogicalTypes;
import org.apache.avro.Schema;
Expand Down Expand Up @@ -102,17 +99,18 @@ public List<ColumnMetadata> extractColumnMetadata(TopicName topicName, SchemaInf
try {
columnMetadata = schema.getFields().stream()
.map(field ->
new PulsarColumnMetadata(PulsarColumnMetadata.getColumnName(handleKeyValueType, field.name()), parseAvroPrestoType(
field.name(), field.schema()), field.schema().toString(), null, false, false,
new PulsarColumnMetadata(PulsarColumnMetadata.getColumnName(handleKeyValueType,
field.name()), parseAvroPrestoType(field.name(), field.schema()),
field.schema().toString(), null, false, false,
handleKeyValueType, new PulsarColumnMetadata.DecoderExtraInfo(field.name(),
null, null))

).collect(toList());
}catch (StackOverflowError e){
} catch (StackOverflowError e){
log.warn(e, "Topic "
+ topicName.toString() + " extractColumnMetadata failed.");
throw new PrestoException(NOT_SUPPORTED, "Topic "
+ topicName.toString() + " schema may contains cyclic definitions.",e);
+ topicName.toString() + " schema may contains cyclic definitions.", e);
}
return columnMetadata;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import static java.lang.Long.parseLong;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
Expand Down Expand Up @@ -73,7 +72,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.tuple.Pair;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static java.util.Objects.requireNonNull;
import static java.util.function.Function.identity;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.MissingNode;
import com.google.common.base.Splitter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import static io.prestosql.spi.type.VarcharType.createUnboundedVarcharType;
import static java.lang.String.format;
import static java.util.stream.Collectors.toList;

import com.google.common.collect.ImmutableList;
import io.airlift.log.Logger;
import io.prestosql.decoder.DecoderColumnHandle;
Expand Down Expand Up @@ -99,7 +98,8 @@ public List<ColumnMetadata> extractColumnMetadata(TopicName topicName, SchemaInf
try {
columnMetadata = schema.getFields().stream()
.map(field ->
new PulsarColumnMetadata(PulsarColumnMetadata.getColumnName(handleKeyValueType, field.name()), parseJsonPrestoType(field.name(), field.schema()),
new PulsarColumnMetadata(PulsarColumnMetadata.getColumnName(handleKeyValueType,
field.name()), parseJsonPrestoType(field.name(), field.schema()),
field.schema().toString(), null, false, false,
handleKeyValueType, new PulsarColumnMetadata.DecoderExtraInfo(
field.name(), null, null))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import static io.prestosql.decoder.FieldValueProviders.bytesValueProvider;
import static io.prestosql.decoder.FieldValueProviders.longValueProvider;
import static org.apache.pulsar.sql.presto.PulsarFieldValueProviders.doubleValueProvider;

import io.netty.buffer.ByteBuf;
import io.prestosql.decoder.DecoderColumnHandle;
import io.prestosql.decoder.FieldValueProvider;
Expand All @@ -40,14 +39,12 @@
import io.prestosql.spi.type.Type;
import io.prestosql.spi.type.VarbinaryType;
import io.prestosql.spi.type.VarcharType;

import java.sql.Time;
import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import org.apache.pulsar.client.impl.schema.AbstractSchema;
import org.apache.pulsar.sql.presto.PulsarRowDecoder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@
import java.util.Arrays;
import java.util.List;
import java.util.Set;

import org.apache.pulsar.client.impl.schema.AutoConsumeSchema;
import org.apache.pulsar.client.impl.schema.AbstractSchema;
import org.apache.pulsar.client.impl.schema.AutoConsumeSchema;
import org.apache.pulsar.common.naming.TopicName;
import org.apache.pulsar.common.schema.SchemaInfo;
import org.apache.pulsar.common.schema.SchemaType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import static java.lang.Float.floatToIntBits;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;

import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet;
import com.google.protobuf.ByteString;
Expand Down Expand Up @@ -142,7 +141,8 @@ private static Object locateNode(DynamicMessage element, String columnMapping) {
if (value == null) {
return null;
}
value = ((DynamicMessage) value).getField(((DynamicMessage) value).getDescriptorForType().findFieldByName(pathElement));
value = ((DynamicMessage) value).getField(((DynamicMessage) value).getDescriptorForType()
.findFieldByName(pathElement));
}
return value;
}
Expand Down Expand Up @@ -351,7 +351,10 @@ private static Block serializeMap(BlockBuilder parentBlockBuilder, Object value,
protected static Map parseProtobufMap(Object value) {
Map map = new HashMap();
for (Object mapMsg : ((List) value)) {
map.put(((DynamicMessage) mapMsg).getField(((DynamicMessage) mapMsg).getDescriptorForType().findFieldByName(PROTOBUF_MAP_KEY_NAME)), ((DynamicMessage) mapMsg).getField(((DynamicMessage) mapMsg).getDescriptorForType().findFieldByName(PROTOBUF_MAP_VALUE_NAME)));
map.put(((DynamicMessage) mapMsg).getField(((DynamicMessage) mapMsg).getDescriptorForType()
.findFieldByName(PROTOBUF_MAP_KEY_NAME)), ((DynamicMessage) mapMsg)
.getField(((DynamicMessage) mapMsg).getDescriptorForType()
.findFieldByName(PROTOBUF_MAP_VALUE_NAME)));
}
return map;
}
Expand All @@ -375,7 +378,8 @@ private static Block serializeRow(BlockBuilder parentBlockBuilder, Object value,
List<Field> fields = ((RowType) type).getFields();
for (Field field : fields) {
checkState(field.getName().isPresent(), "field name not found");
serializeObject(singleRowBuilder, record.getField(((DynamicMessage) value).getDescriptorForType().findFieldByName(field.getName().get())), field.getType(), columnName);
serializeObject(singleRowBuilder, record.getField(((DynamicMessage) value).getDescriptorForType()
.findFieldByName(field.getName().get())), field.getType(), columnName);

}
blockBuilder.closeEntry();
Expand Down
Loading

0 comments on commit d42d30e

Please sign in to comment.