You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by ja...@apache.org on 2014/09/12 17:17:42 UTC
[33/37] DRILL-1402: Add check-style rules for trailing space,
TABs and blocks without braces
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
index 7b4c3d6..2854c14 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
@@ -93,9 +93,9 @@ public class ExpressionTreeMaterializer {
out = out.accept(ConditionalExprOptimizer.INSTANCE, null);
}
- if(out instanceof NullExpression){
+ if (out instanceof NullExpression) {
return new TypedNullConstant(Types.optional(MinorType.INT));
- }else{
+ } else {
return out;
}
}
@@ -258,7 +258,7 @@ public class ExpressionTreeMaterializer {
boolean first = true;
for(LogicalExpression e : call.args) {
TypeProtos.MajorType mt = e.getMajorType();
- if(first){
+ if (first) {
first = false;
} else {
sb.append(", ");
@@ -482,7 +482,7 @@ public class ExpressionTreeMaterializer {
}
@Override
- public LogicalExpression visitCastExpression(CastExpression e, FunctionImplementationRegistry value){
+ public LogicalExpression visitCastExpression(CastExpression e, FunctionImplementationRegistry value) {
// if the cast is pointless, remove it.
LogicalExpression input = e.getInput().accept(this, value);
@@ -490,9 +490,11 @@ public class ExpressionTreeMaterializer {
MajorType newMajor = e.getMajorType();
MinorType newMinor = input.getMajorType().getMinorType();
- if(castEqual(e.getPosition(), newMajor, input.getMajorType())) return input; // don't do pointless cast.
+ if (castEqual(e.getPosition(), newMajor, input.getMajorType())) {
+ return input; // don't do pointless cast.
+ }
- if(newMinor == MinorType.LATE){
+ if (newMinor == MinorType.LATE) {
// if the type still isn't fully bound, leave as cast expression.
return new CastExpression(input, e.getMajorType(), e.getPosition());
} else if (newMinor == MinorType.NULL) {
@@ -520,9 +522,11 @@ public class ExpressionTreeMaterializer {
}
}
- private boolean castEqual(ExpressionPosition pos, MajorType from, MajorType to){
- if(!from.getMinorType().equals(to.getMinorType())) return false;
- switch(from.getMinorType()){
+ private boolean castEqual(ExpressionPosition pos, MajorType from, MajorType to) {
+ if (!from.getMinorType().equals(to.getMinorType())) {
+ return false;
+ }
+ switch(from.getMinorType()) {
case FLOAT4:
case FLOAT8:
case INT:
@@ -564,10 +568,10 @@ public class ExpressionTreeMaterializer {
case VAR16CHAR:
case VARBINARY:
case VARCHAR:
- if(to.getWidth() < from.getWidth() && to.getWidth() > 0){
+ if (to.getWidth() < from.getWidth() && to.getWidth() > 0) {
this.errorCollector.addGeneralError(pos, "Casting from a longer variable length type to a shorter variable length type is not currently supported.");
return false;
- }else{
+ } else {
return true;
}
@@ -577,4 +581,5 @@ public class ExpressionTreeMaterializer {
}
}
}
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFuncHolder.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFuncHolder.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFuncHolder.java
index fcc0b35..1852731 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFuncHolder.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFuncHolder.java
@@ -123,17 +123,17 @@ public abstract class DrillFuncHolder extends AbstractFuncHolder {
WorkspaceReference ref = workspaceVars[i];
JType jtype = g.getModel()._ref(ref.type);
- if(ScalarReplacementTypes.CLASSES.contains(ref.type)){
+ if (ScalarReplacementTypes.CLASSES.contains(ref.type)) {
workspaceJVars[i] = g.declareClassField("work", jtype);
JBlock b = g.getBlock(SignatureHolder.DRILL_INIT_METHOD);
b.assign(workspaceJVars[i], JExpr._new(jtype));
- }else{
+ } else {
workspaceJVars[i] = g.declareClassField("work", jtype);
}
- if(ref.isInject()){
+ if (ref.isInject()) {
g.getBlock(BlockType.SETUP).assign(workspaceJVars[i], g.getMappingSet().getIncoming().invoke("getContext").invoke("getManagedBuffer"));
- }else{
+ } else {
//g.getBlock(BlockType.SETUP).assign(workspaceJVars[i], JExpr._new(jtype));
}
}
@@ -159,8 +159,9 @@ public abstract class DrillFuncHolder extends AbstractFuncHolder {
JVar[] workspaceJVars, boolean decConstInputOnly) {
if (inputVariables != null) {
for (int i = 0; i < inputVariables.length; i++) {
- if (decConstInputOnly && !inputVariables[i].isConstant())
+ if (decConstInputOnly && !inputVariables[i].isConstant()) {
continue;
+ }
ValueReference parameter = parameters[i];
HoldingContainer inputVariable = inputVariables[i];
@@ -177,10 +178,9 @@ public abstract class DrillFuncHolder extends AbstractFuncHolder {
JVar[] internalVars = new JVar[workspaceJVars.length];
for (int i = 0; i < workspaceJVars.length; i++) {
- if(decConstInputOnly){
+ if (decConstInputOnly) {
internalVars[i] = sub.decl(g.getModel()._ref(workspaceVars[i].type), workspaceVars[i].name, workspaceJVars[i]);
- }else{
-
+ } else {
internalVars[i] = sub.decl(g.getModel()._ref(workspaceVars[i].type), workspaceVars[i].name, workspaceJVars[i]);
}
@@ -313,7 +313,6 @@ public abstract class DrillFuncHolder extends AbstractFuncHolder {
MajorType type = Types.required(MinorType.LATE);
ValueReference ref = new ValueReference(type, name);
ref.isComplexWriter = true;
-
return ref;
}
@@ -342,7 +341,7 @@ public abstract class DrillFuncHolder extends AbstractFuncHolder {
this.majorType = majorType;
}
- public boolean isInject(){
+ public boolean isInject() {
return inject;
}
}
@@ -358,4 +357,5 @@ public abstract class DrillFuncHolder extends AbstractFuncHolder {
public ValueReference getReturnValue() {
return returnValue;
}
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFunctionRegistry.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFunctionRegistry.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFunctionRegistry.java
index f53bd28..399f302 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFunctionRegistry.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFunctionRegistry.java
@@ -39,16 +39,18 @@ public class DrillFunctionRegistry {
private ArrayListMultimap<String, DrillFuncHolder> methods = ArrayListMultimap.create();
- public DrillFunctionRegistry(DrillConfig config){
+ public DrillFunctionRegistry(DrillConfig config) {
FunctionConverter converter = new FunctionConverter();
Set<Class<? extends DrillFunc>> providerClasses = PathScanner.scanForImplementations(DrillFunc.class, config.getStringList(ExecConstants.FUNCTION_PACKAGES));
for (Class<? extends DrillFunc> clazz : providerClasses) {
DrillFuncHolder holder = converter.getHolder(clazz);
- if(holder != null){
+ if (holder != null) {
// register handle for each name the function can be referred to
String[] names = holder.getRegisteredNames();
- for(String name : names) methods.put(name.toLowerCase(), holder);
- }else{
+ for (String name : names) {
+ methods.put(name.toLowerCase(), holder);
+ }
+ } else {
logger.warn("Unable to initialize function for class {}", clazz.getName());
}
}
@@ -83,4 +85,5 @@ public class DrillFunctionRegistry {
}
}
}
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillSimpleFuncHolder.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillSimpleFuncHolder.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillSimpleFuncHolder.java
index 397cf92..4731200 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillSimpleFuncHolder.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillSimpleFuncHolder.java
@@ -65,15 +65,15 @@ class DrillSimpleFuncHolder extends DrillFuncHolder{
}
@Override
- public boolean isNested(){
+ public boolean isNested() {
return false;
}
@Override
- public HoldingContainer renderEnd(ClassGenerator<?> g, HoldingContainer[] inputVariables, JVar[] workspaceJVars){
+ public HoldingContainer renderEnd(ClassGenerator<?> g, HoldingContainer[] inputVariables, JVar[] workspaceJVars) {
//If the function's annotation specifies a parameter has to be constant expression, but the HoldingContainer
//for the argument is not, then raise exception.
- for(int i =0; i < inputVariables.length; i++){
+ for (int i =0; i < inputVariables.length; i++) {
if (parameters[i].isConstant && !inputVariables[i].isConstant()) {
throw new DrillRuntimeException(String.format("The argument '%s' of Function '%s' has to be constant!", parameters[i].name, this.getRegisteredNames()[0]));
}
@@ -95,19 +95,19 @@ class DrillSimpleFuncHolder extends DrillFuncHolder{
MajorType returnValueType = returnValue.type;
// add outside null handling if it is defined.
- if(nullHandling == NullHandling.NULL_IF_NULL){
+ if (nullHandling == NullHandling.NULL_IF_NULL) {
JExpression e = null;
- for(HoldingContainer v : inputVariables){
- if(v.isOptional()){
- if(e == null){
+ for (HoldingContainer v : inputVariables) {
+ if (v.isOptional()) {
+ if (e == null) {
e = v.getIsSet();
- }else{
+ } else {
e = e.mul(v.getIsSet());
}
}
}
- if(e != null){
+ if (e != null) {
// if at least one expression must be checked, set up the conditional.
returnValueType = returnValue.type.toBuilder().setMode(DataMode.OPTIONAL).build();
out = g.declare(returnValueType);
@@ -118,7 +118,9 @@ class DrillSimpleFuncHolder extends DrillFuncHolder{
}
}
- if(out == null) out = g.declare(returnValueType);
+ if (out == null) {
+ out = g.declare(returnValueType);
+ }
// add the subblock after the out declaration.
g.getEvalBlock().add(topSub);
@@ -126,9 +128,13 @@ class DrillSimpleFuncHolder extends DrillFuncHolder{
JVar internalOutput = sub.decl(JMod.FINAL, g.getHolderType(returnValueType), returnValue.name, JExpr._new(g.getHolderType(returnValueType)));
addProtectedBlock(g, sub, body, inputVariables, workspaceJVars, false);
- if (sub != topSub) sub.assign(internalOutput.ref("isSet"),JExpr.lit(1));// Assign null if NULL_IF_NULL mode
+ if (sub != topSub) {
+ sub.assign(internalOutput.ref("isSet"),JExpr.lit(1));// Assign null if NULL_IF_NULL mode
+ }
sub.assign(out.getHolder(), internalOutput);
- if (sub != topSub) sub.assign(internalOutput.ref("isSet"),JExpr.lit(1));// Assign null if NULL_IF_NULL mode
+ if (sub != topSub) {
+ sub.assign(internalOutput.ref("isSet"),JExpr.lit(1));// Assign null if NULL_IF_NULL mode
+ }
g.getEvalBlock().directStatement(String.format("//---- end of eval portion of %s function. ----//", registeredNames[0]));
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionConverter.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionConverter.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionConverter.java
index 63ddb11..402a6fc 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionConverter.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionConverter.java
@@ -67,12 +67,14 @@ public class FunctionConverter {
path = path.replace(".", FileUtils.separator);
path = "/" + path + ".java";
CompilationUnit cu = functionUnits.get(path);
- if(cu != null) return cu;
+ if(cu != null) {
+ return cu;
+ }
URL u = Resources.getResource(c, path);
InputSupplier<InputStream> supplier = Resources.newInputStreamSupplier(u);
- try(InputStream is = supplier.getInput()){
- if(is == null){
+ try (InputStream is = supplier.getInput()) {
+ if (is == null) {
throw new IOException(String.format("Failure trying to located source code for Class %s, tried to read on classpath location %s", c.getName(), path));
}
String body = IO.toString(is);
@@ -92,9 +94,9 @@ public class FunctionConverter {
}
- public <T extends DrillFunc> DrillFuncHolder getHolder(Class<T> clazz){
+ public <T extends DrillFunc> DrillFuncHolder getHolder(Class<T> clazz) {
FunctionTemplate template = clazz.getAnnotation(FunctionTemplate.class);
- if(template == null){
+ if (template == null) {
return failure("Class does not declare FunctionTemplate annotation.", clazz);
}
@@ -110,7 +112,7 @@ public class FunctionConverter {
ValueReference outputField = null;
- for(Field field : clazz.getDeclaredFields()){
+ for (Field field : clazz.getDeclaredFields()) {
Param param = field.getAnnotation(Param.class);
Output output = field.getAnnotation(Output.class);
@@ -118,17 +120,25 @@ public class FunctionConverter {
Inject inject = field.getAnnotation(Inject.class);
int i =0;
- if(param != null) i++;
- if(output != null) i++;
- if(workspace != null) i++;
- if(inject != null) i++;
- if(i == 0){
+ if (param != null) {
+ i++;
+ }
+ if (output != null) {
+ i++;
+ }
+ if (workspace != null) {
+ i++;
+ }
+ if (inject != null) {
+ i++;
+ }
+ if (i == 0) {
return failure("The field must be either a @Param, @Output, @Inject or @Workspace field.", clazz, field);
- }else if(i > 1){
+ } else if(i > 1) {
return failure("The field must be only one of @Param, @Output, @Inject or @Workspace. It currently has more than one of these annotations.", clazz, field);
}
- if(param != null || output != null){
+ if (param != null || output != null) {
// Special processing for @Param FieldReader
if (param != null && FieldReader.class.isAssignableFrom(field.getType())) {
@@ -138,8 +148,7 @@ public class FunctionConverter {
// Special processing for @Output ComplexWriter
if (output != null && ComplexWriter.class.isAssignableFrom(field.getType())) {
-
- if(outputField != null){
+ if (outputField != null) {
return failure("You've declared more than one @Output field. You must declare one and only @Output field per Function class.", clazz, field);
}else{
outputField = ValueReference.createComplexWriterRef(field.getName());
@@ -148,37 +157,39 @@ public class FunctionConverter {
}
// check that param and output are value holders.
- if(!ValueHolder.class.isAssignableFrom(field.getType())){
+ if (!ValueHolder.class.isAssignableFrom(field.getType())) {
return failure(String.format("The field doesn't holds value of type %s which does not implement the ValueHolder interface. All fields of type @Param or @Output must extend this interface..", field.getType()), clazz, field);
}
// get the type field from the value holder.
MajorType type = null;
- try{
+ try {
type = getStaticFieldValue("TYPE", field.getType(), MajorType.class);
- }catch(Exception e){
+ } catch (Exception e) {
return failure("Failure while trying to access the ValueHolder's TYPE static variable. All ValueHolders must contain a static TYPE variable that defines their MajorType.", e, clazz, field.getName());
}
ValueReference p = new ValueReference(type, field.getName());
- if(param != null){
+ if (param != null) {
if (param.constant()) {
p.setConstant(true);
}
params.add(p);
- }else{
- if(outputField != null){
+ } else {
+ if (outputField != null) {
return failure("You've declared more than one @Output field. You must declare one and only @Output field per Function class.", clazz, field);
- }else{
+ } else {
outputField = p;
}
}
- }else{
+ } else {
// workspace work.
boolean isInject = inject != null;
- if(isInject && !field.getType().equals(DrillBuf.class)) return failure(String.format("Only DrillBuf is allowed to be injected. You attempted to inject %s.", field.getType()), clazz, field);
+ if (isInject && !field.getType().equals(DrillBuf.class)) {
+ return failure(String.format("Only DrillBuf is allowed to be injected. You attempted to inject %s.", field.getType()), clazz, field);
+ }
WorkspaceReference wsReference = new WorkspaceReference(field.getType(), field.getName(), isInject);
if (!isInject && template.scope() == FunctionScope.POINT_AGGREGATE && !ValueHolder.class.isAssignableFrom(field.getType()) ) {
@@ -186,31 +197,32 @@ public class FunctionConverter {
}
//If the workspace var is of Holder type, get its MajorType and assign to WorkspaceReference.
- if(ValueHolder.class.isAssignableFrom(field.getType())){
+ if (ValueHolder.class.isAssignableFrom(field.getType())) {
MajorType majorType = null;
- try{
+ try {
majorType = getStaticFieldValue("TYPE", field.getType(), MajorType.class);
- }catch(Exception e){
+ } catch (Exception e) {
return failure("Failure while trying to access the ValueHolder's TYPE static variable. All ValueHolders must contain a static TYPE variable that defines their MajorType.", e, clazz, field.getName());
}
wsReference.setMajorType(majorType);
}
-
workspaceFields.add(wsReference);
}
-
}
-
- // if(!workspaceFields.isEmpty()) return failure("This function declares one or more workspace fields. However, those have not yet been implemented.", clazz);
- if(outputField == null) return failure("This function declares zero output fields. A function must declare one output field.", clazz);
+ // if (!workspaceFields.isEmpty()) return failure("This function declares one or more workspace fields. However, those have not yet been implemented.", clazz);
+ if (outputField == null) {
+ return failure("This function declares zero output fields. A function must declare one output field.", clazz);
+ }
// get function body.
CompilationUnit cu;
try {
cu = get(clazz);
- if(cu == null) return null;
+ if (cu == null) {
+ return null;
+ }
} catch (IOException e) {
return failure("Failure while getting class body.", e, clazz);
}
@@ -225,7 +237,7 @@ public class FunctionConverter {
String[] registeredNames = ((template.name().isEmpty()) ? template.names() : new String[] {template.name()} );
- switch(template.scope()){
+ switch (template.scope()) {
case POINT_AGGREGATE:
return new DrillAggFuncHolder(template.scope(), template.nulls(), template.isBinaryCommutative(),
template.isRandom(), registeredNames, ps, outputField, works, methods, imports, template.costCategory());
@@ -236,16 +248,17 @@ public class FunctionConverter {
return new DrillDecimalSumAggFuncHolder(template.scope(), template.nulls(), template.isBinaryCommutative(),
template.isRandom(), registeredNames, ps, outputField, works, methods, imports);
case SIMPLE:
- if (outputField.isComplexWriter)
+ if (outputField.isComplexWriter) {
return new DrillComplexWriterFuncHolder(template.scope(), template.nulls(),
template.isBinaryCommutative(),
template.isRandom(), registeredNames,
ps, outputField, works, methods, imports);
- else
+ } else {
return new DrillSimpleFuncHolder(template.scope(), template.nulls(),
template.isBinaryCommutative(),
template.isRandom(), registeredNames,
ps, outputField, works, methods, imports, template.costCategory());
+ }
case SC_BOOLEAN_OPERATOR:
return new DrillBooleanOPHolder(template.scope(), template.nulls(),
template.isBinaryCommutative(),
@@ -281,7 +294,7 @@ public class FunctionConverter {
default:
return failure("Unsupported Function Type.", clazz);
}
- }catch(Exception | NoSuchFieldError | AbstractMethodError ex){
+ } catch (Exception | NoSuchFieldError | AbstractMethodError ex) {
return failure("Failure while creating function holder.", ex, clazz);
}
@@ -296,8 +309,8 @@ public class FunctionConverter {
path = "/" + path + ".java";
URL u = Resources.getResource(c, path);
InputSupplier<InputStream> supplier = Resources.newInputStreamSupplier(u);
- try(InputStream is = supplier.getInput()){
- if(is == null){
+ try (InputStream is = supplier.getInput()) {
+ if (is == null) {
throw new IOException(String.format("Failure trying to located source code for Class %s, tried to read on classpath location %s", c.getName(), path));
}
String body = IO.toString(is);
@@ -318,30 +331,28 @@ public class FunctionConverter {
return (T) val;
}
- private static DrillFuncHolder failure(String message, Throwable t, Class<?> clazz, String fieldName){
+ private static DrillFuncHolder failure(String message, Throwable t, Class<?> clazz, String fieldName) {
logger.warn("Failure loading function class {}, field {}. " + message, clazz.getName(), fieldName, t);
return null;
}
- private DrillFuncHolder failure(String message, Class<?> clazz, String fieldName){
+ private DrillFuncHolder failure(String message, Class<?> clazz, String fieldName) {
logger.warn("Failure loading function class {}, field {}. " + message, clazz.getName(), fieldName);
return null;
}
- private DrillFuncHolder failure(String message, Class<?> clazz){
+ private DrillFuncHolder failure(String message, Class<?> clazz) {
logger.warn("Failure loading function class [{}]. Message: {}", clazz.getName(), message);
return null;
}
- private DrillFuncHolder failure(String message, Throwable t, Class<?> clazz){
+ private DrillFuncHolder failure(String message, Throwable t, Class<?> clazz) {
logger.warn("Failure loading function class [{}]. Message: {}", clazz.getName(), message, t);
return null;
}
- private DrillFuncHolder failure(String message, Class<?> clazz, Field field){
+ private DrillFuncHolder failure(String message, Class<?> clazz, Field field) {
return failure(message, clazz, field.getName());
}
-
-
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionGenerationHelper.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionGenerationHelper.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionGenerationHelper.java
index 293fbf7..e0f7f93 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionGenerationHelper.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionGenerationHelper.java
@@ -45,11 +45,10 @@ public class FunctionGenerationHelper {
return getFunctionExpression(COMPARE_TO, Types.required(MinorType.INT), registry, left, right);
}
- public static FunctionHolderExpression getFunctionExpression(String name, MajorType returnType, FunctionImplementationRegistry registry, HoldingContainer... args){
-
+ public static FunctionHolderExpression getFunctionExpression(String name, MajorType returnType, FunctionImplementationRegistry registry, HoldingContainer... args) {
List<MajorType> argTypes = new ArrayList<MajorType>(args.length);
List<LogicalExpression> argExpressions = new ArrayList<LogicalExpression>(args.length);
- for(HoldingContainer c : args){
+ for(HoldingContainer c : args) {
argTypes.add(c.getMajorType());
argExpressions.add(new HoldingContainerExpression(c));
}
@@ -63,19 +62,22 @@ public class FunctionGenerationHelper {
sb.append("Failure finding function that runtime code generation expected. Signature: ");
sb.append(name);
sb.append("( ");
- for(int i =0; i < args.length; i++){
+ for(int i =0; i < args.length; i++) {
MajorType mt = args[i].getMajorType();
appendType(mt, sb);
- if(i != 0) sb.append(", ");
+ if (i != 0) {
+ sb.append(", ");
+ }
}
sb.append(" ) returns ");
appendType(returnType, sb);
throw new UnsupportedOperationException(sb.toString());
}
- private static final void appendType(MajorType mt, StringBuilder sb){
+ private static final void appendType(MajorType mt, StringBuilder sb) {
sb.append(mt.getMinorType().name());
sb.append(":");
sb.append(mt.getMode().name());
}
-}
\ No newline at end of file
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/ModifiedUnparseVisitor.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/ModifiedUnparseVisitor.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/ModifiedUnparseVisitor.java
index aea46e8..966c465 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/ModifiedUnparseVisitor.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/ModifiedUnparseVisitor.java
@@ -100,7 +100,9 @@ public class ModifiedUnparseVisitor extends UnparseVisitor {
bs instanceof Java.SynchronizedStatement ? 4 :
99
);
- if (state != -1 && state != x) this.pw.println(AutoIndentWriter.CLEAR_TABULATORS);
+ if (state != -1 && state != x) {
+ this.pw.println(AutoIndentWriter.CLEAR_TABULATORS);
+ }
state = x;
this.unparseBlockStatement(bs);
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteFunctionHelpers.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteFunctionHelpers.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteFunctionHelpers.java
index 8c55aa9..d21add1 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteFunctionHelpers.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteFunctionHelpers.java
@@ -92,7 +92,7 @@ public class ByteFunctionHelpers {
while (n > 7) {
long leftLong = PlatformDependent.getLong(lPos);
long rightLong = PlatformDependent.getLong(rPos);
- if(leftLong != rightLong){
+ if (leftLong != rightLong) {
return UnsignedLongs.compare(Long.reverseBytes(leftLong), Long.reverseBytes(rightLong));
}
lPos += 8;
@@ -110,7 +110,9 @@ public class ByteFunctionHelpers {
rPos++;
}
- if (lLen == rLen) return 0;
+ if (lLen == rLen) {
+ return 0;
+ }
return lLen > rLen ? 1 : -1;
@@ -134,8 +136,6 @@ public class ByteFunctionHelpers {
long lPos = laddr + lStart;
int rPos = rStart;
-
-
while (n-- != 0) {
byte leftByte = PlatformDependent.getByte(lPos);
byte rightByte = right[rPos];
@@ -146,10 +146,11 @@ public class ByteFunctionHelpers {
rPos++;
}
- if (lLen == rLen) return 0;
+ if (lLen == rLen) {
+ return 0;
+ }
return lLen > rLen ? 1 : -1;
-
}
/*
@@ -201,4 +202,5 @@ public class ByteFunctionHelpers {
public static boolean getSign(byte[] b) {
return ((getInteger(b, 0, false) & 0x80000000) != 0);
}
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteSubstring.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteSubstring.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteSubstring.java
index ad2efa2..55dc35a 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteSubstring.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteSubstring.java
@@ -67,17 +67,20 @@ public class ByteSubstring implements DrillSimpleFunc {
} else {
// handle negative and positive offset values
- if (offset.value < 0)
+ if (offset.value < 0) {
out.start = string.end + (int)offset.value;
- else
+ } else {
out.start = (int)offset.value - 1;
+ }
// calculate end position from length and truncate to upper value bounds
- if (out.start + length.value > string.end)
+ if (out.start + length.value > string.end) {
out.end = string.end;
- else
+ } else {
out.end = out.start + (int)length.value;
+ }
}
}
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CharSubstring.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CharSubstring.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CharSubstring.java
index 5fdc6f2..62e9d70 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CharSubstring.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CharSubstring.java
@@ -89,8 +89,9 @@ public class CharSubstring implements DrillSimpleFunc {
break;
}
- if (currentByte < 128)
+ if (currentByte < 128) {
++charCount;
+ }
++byteCount;
}
@@ -112,8 +113,9 @@ public class CharSubstring implements DrillSimpleFunc {
// search forward until we find <length> characters
while (byteCount <= endBytePos) {
currentByte = string.buffer.getByte(byteCount);
- if (currentByte < 128)
+ if (currentByte < 128) {
++charCount;
+ }
++byteCount;
if (charCount == (int)length.value) {
out.end = byteCount;
@@ -122,8 +124,9 @@ public class CharSubstring implements DrillSimpleFunc {
}
break;
}
- if (currentByte < 128)
+ if (currentByte < 128) {
--charCount;
+ }
--byteCount;
}
}
@@ -134,4 +137,5 @@ public class CharSubstring implements DrillSimpleFunc {
}
}
}
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/HashFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/HashFunctions.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/HashFunctions.java
index 7c847eb..7f6d8a5 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/HashFunctions.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/HashFunctions.java
@@ -66,10 +66,11 @@ public class HashFunctions {
}
public void eval() {
- if (in.isSet == 0)
+ if (in.isSet == 0) {
out.value = 0;
- else
+ } else {
out.value = com.google.common.hash.Hashing.murmur3_128().hashInt(Float.floatToIntBits(in.value)).asInt();
+ }
}
}
@@ -97,10 +98,11 @@ public class HashFunctions {
}
public void eval() {
- if (in.isSet == 0)
+ if (in.isSet == 0) {
out.value = 0;
- else
+ } else {
out.value = com.google.common.hash.Hashing.murmur3_128().hashLong(Double.doubleToLongBits(in.value)).asInt();
+ }
}
}
@@ -128,10 +130,11 @@ public class HashFunctions {
}
public void eval() {
- if (in.isSet == 0)
+ if (in.isSet == 0) {
out.value = 0;
- else
+ } else {
out.value = org.apache.drill.exec.expr.fn.impl.HashHelper.hash(in.buffer.nioBuffer(in.start, in.end - in.start), 0);
+ }
}
}
@@ -145,10 +148,11 @@ public class HashFunctions {
}
public void eval() {
- if (in.isSet == 0)
+ if (in.isSet == 0) {
out.value = 0;
- else
+ } else {
out.value = org.apache.drill.exec.expr.fn.impl.HashHelper.hash(in.buffer.nioBuffer(in.start, in.end - in.start), 0);
+ }
}
}
@@ -162,10 +166,11 @@ public class HashFunctions {
}
public void eval() {
- if (in.isSet == 0)
+ if (in.isSet == 0) {
out.value = 0;
- else
+ } else {
out.value = org.apache.drill.exec.expr.fn.impl.HashHelper.hash(in.buffer.nioBuffer(in.start, in.end - in.start), 0);
+ }
}
}
@@ -180,10 +185,11 @@ public class HashFunctions {
public void eval() {
// TODO: implement hash function for other types
- if (in.isSet == 0)
+ if (in.isSet == 0) {
out.value = 0;
- else
+ } else {
out.value = com.google.common.hash.Hashing.murmur3_128().hashLong(in.value).asInt();
+ }
}
}
@@ -197,10 +203,11 @@ public class HashFunctions {
public void eval() {
// TODO: implement hash function for other types
- if (in.isSet == 0)
+ if (in.isSet == 0) {
out.value = 0;
- else
+ } else {
out.value = com.google.common.hash.Hashing.murmur3_128().hashInt(in.value).asInt();
+ }
}
}
@@ -296,10 +303,11 @@ public class HashFunctions {
}
public void eval() {
- if (in.isSet == 0)
+ if (in.isSet == 0) {
out.value = 0;
- else
+ } else {
out.value = com.google.common.hash.Hashing.murmur3_128().hashLong(in.value).asInt();
+ }
}
}
@@ -325,10 +333,11 @@ public class HashFunctions {
}
public void eval() {
- if (in.isSet == 0)
+ if (in.isSet == 0) {
out.value = 0;
- else
+ } else {
out.value = com.google.common.hash.Hashing.murmur3_128().hashLong(in.value).asInt();
+ }
}
}
@@ -354,10 +363,11 @@ public class HashFunctions {
}
public void eval() {
- if (in.isSet == 0)
+ if (in.isSet == 0) {
out.value = 0;
- else
+ } else {
out.value = com.google.common.hash.Hashing.murmur3_128().hashInt(in.value).asInt();
+ }
}
}
@@ -383,10 +393,11 @@ public class HashFunctions {
}
public void eval() {
- if (in.isSet == 0)
+ if (in.isSet == 0) {
out.value = 0;
- else
+ } else {
out.value = com.google.common.hash.Hashing.murmur3_128().hashLong(in.value ^ in.index).asInt();
+ }
}
}
@@ -412,10 +423,11 @@ public class HashFunctions {
}
public void eval() {
- if (in.isSet == 0)
+ if (in.isSet == 0) {
out.value = 0;
- else
+ } else {
out.value = com.google.common.hash.Hashing.murmur3_128().hashInt(in.value).asInt();
+ }
}
}
@@ -441,10 +453,11 @@ public class HashFunctions {
}
public void eval() {
- if (in.isSet == 0)
+ if (in.isSet == 0) {
out.value = 0;
- else
+ } else {
out.value = com.google.common.hash.Hashing.murmur3_128().hashLong(in.value).asInt();
+ }
}
}
@@ -475,9 +488,9 @@ public class HashFunctions {
}
public void eval() {
- if (in.isSet == 0)
+ if (in.isSet == 0) {
out.value = 0;
- else {
+ } else {
int xor = 0;
for (int i = 0; i < in.nDecimalDigits; i++) {
xor = xor ^ NullableDecimal28SparseHolder.getInteger(i, in.start, in.buffer);
@@ -514,9 +527,9 @@ public class HashFunctions {
}
public void eval() {
- if (in.isSet == 0)
+ if (in.isSet == 0) {
out.value = 0;
- else {
+ } else {
int xor = 0;
for (int i = 0; i < in.nDecimalDigits; i++) {
xor = xor ^ NullableDecimal38SparseHolder.getInteger(i, in.start, in.buffer);
@@ -525,4 +538,5 @@ public class HashFunctions {
}
}
}
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsFalse.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsFalse.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsFalse.java
index 52af8cd..72378e2 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsFalse.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsFalse.java
@@ -37,10 +37,11 @@ public class IsFalse {
public void setup(RecordBatch incoming) { }
public void eval() {
- if (in.isSet == 0)
+ if (in.isSet == 0) {
out.value = 0;
- else
+ } else {
out.value = (in.value == 0 ? 1 : 0);
+ }
}
}
@@ -57,4 +58,4 @@ public class IsFalse {
}
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotFalse.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotFalse.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotFalse.java
index 65476ae..07f420c 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotFalse.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotFalse.java
@@ -37,10 +37,11 @@ public class IsNotFalse {
public void setup(RecordBatch incoming) { }
public void eval() {
- if (in.isSet == 0)
+ if (in.isSet == 0) {
out.value = 1;
- else
+ } else {
out.value = in.value;
+ }
}
}
@@ -57,4 +58,4 @@ public class IsNotFalse {
}
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotTrue.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotTrue.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotTrue.java
index 3f389af..a7a87a3 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotTrue.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsNotTrue.java
@@ -37,10 +37,11 @@ public class IsNotTrue {
public void setup(RecordBatch incoming) { }
public void eval() {
- if (in.isSet == 0)
+ if (in.isSet == 0) {
out.value = 1;
- else
+ } else {
out.value = (in.value == 0 ? 1 : 0);
+ }
}
}
@@ -56,4 +57,5 @@ public class IsNotTrue {
out.value = in.value == 0 ? 1 : 0;
}
}
-}
\ No newline at end of file
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsTrue.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsTrue.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsTrue.java
index 7edf539..d534b7d 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsTrue.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/IsTrue.java
@@ -37,10 +37,11 @@ public class IsTrue {
public void setup(RecordBatch incoming) { }
public void eval() {
- if (in.isSet == 0)
+ if (in.isSet == 0) {
out.value = 0;
- else
+ } else {
out.value = in.value;
+ }
}
}
@@ -56,4 +57,5 @@ public class IsTrue {
out.value = in.value;
}
}
-}
\ No newline at end of file
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctionUtil.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctionUtil.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctionUtil.java
index 3b7efbd..dedd89e 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctionUtil.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctionUtil.java
@@ -42,8 +42,9 @@ public class StringFunctionUtil {
public static int getUTF8CharPosition(ByteBuf buffer, int start, int end, int charLength) {
int charCount = 0;
- if (start >= end)
+ if (start >= end) {
return -1; //wrong input here.
+ }
for (int idx = start, charLen = 0; idx < end; idx += charLen) {
charLen = utf8CharLen(buffer, idx);
@@ -60,8 +61,9 @@ public class StringFunctionUtil {
for (int i = strStart; i <= strEnd - (subEnd - subStart); i++) {
int j = subStart;
for (; j< subEnd; j++) {
- if (str.getByte(i + j - subStart) != substr.getByte(j))
+ if (str.getByte(i + j - subStart) != substr.getByte(j)) {
break;
+ }
}
if (j == subEnd && j!= subStart) { // found a matched substr (non-empty) in str.
@@ -88,18 +90,19 @@ public class StringFunctionUtil {
}
public static int utf8CharLen(byte currentByte) {
- if (currentByte >= 0){ // 1-byte char. First byte is 0xxxxxxx.
- return 1;
+ if (currentByte >= 0) { // 1-byte char. First byte is 0xxxxxxx.
+ return 1;
}
- else if ((currentByte & 0xE0) == 0xC0 ){ // 2-byte char. First byte is 110xxxxx
- return 2;
+ else if ((currentByte & 0xE0) == 0xC0 ) { // 2-byte char. First byte is 110xxxxx
+ return 2;
}
- else if ((currentByte & 0xF0) == 0xE0 ){ // 3-byte char. First byte is 1110xxxx
- return 3;
+ else if ((currentByte & 0xF0) == 0xE0 ) { // 3-byte char. First byte is 1110xxxx
+ return 3;
}
- else if ((currentByte & 0xF8) == 0xF0){ //4-byte char. First byte is 11110xxx
- return 4;
+ else if ((currentByte & 0xF8) == 0xF0) { //4-byte char. First byte is 11110xxx
+ return 4;
}
throw new DrillRuntimeException("Unexpected byte 0x" + Integer.toString((int)currentByte & 0xff, 16) + " encountered while decoding UTF8 string.");
}
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
index 0fa0da2..9883f25 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
@@ -43,7 +43,7 @@ import org.apache.drill.exec.record.RecordBatch;
public class StringFunctions{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(StringFunctions.class);
- private StringFunctions(){}
+ private StringFunctions() {}
/*
* String Function Implementation.
@@ -57,12 +57,12 @@ public class StringFunctions{
@Output BitHolder out;
@Workspace java.util.regex.Matcher matcher;
- public void setup(RecordBatch incoming){
+ public void setup(RecordBatch incoming) {
matcher = java.util.regex.Pattern.compile(org.apache.drill.exec.expr.fn.impl.RegexpUtil.sqlToRegexLike( //
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(pattern.start, pattern.end, pattern.buffer))).matcher("");
}
- public void eval(){
+ public void eval() {
String i = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(input.start, input.end, input.buffer);
matcher.reset(i);
out.value = matcher.matches()? 1:0;
@@ -76,12 +76,12 @@ public class StringFunctions{
@Output BitHolder out;
@Workspace java.util.regex.Matcher matcher;
- public void setup(RecordBatch incoming){
+ public void setup(RecordBatch incoming) {
matcher = java.util.regex.Pattern.compile(org.apache.drill.exec.expr.fn.impl.RegexpUtil.sqlToRegexSimilar(org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(pattern.start, pattern.end, pattern.buffer))).matcher("");
}
- public void eval(){
+ public void eval() {
String i = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(input.start, input.end, input.buffer);
matcher.reset(i);
out.value = matcher.matches()? 1:0;
@@ -101,11 +101,11 @@ public class StringFunctions{
@Workspace java.util.regex.Matcher matcher;
@Output VarCharHolder out;
- public void setup(RecordBatch incoming){
+ public void setup(RecordBatch incoming) {
matcher = java.util.regex.Pattern.compile(org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(pattern.start, pattern.end, pattern.buffer)).matcher("");
}
- public void eval(){
+ public void eval() {
out.start = 0;
String i = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(input.start, input.end, input.buffer);
@@ -117,16 +117,15 @@ public class StringFunctions{
}
}
-
@FunctionTemplate(names = {"char_length", "character_length", "length"}, scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
public static class CharLength implements DrillSimpleFunc{
@Param VarCharHolder input;
@Output BigIntHolder out;
- public void setup(RecordBatch incoming){}
+ public void setup(RecordBatch incoming) {}
- public void eval(){
+ public void eval() {
out.value = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.getUTF8CharLength(input.buffer, input.start, input.end);
}
}
@@ -137,9 +136,9 @@ public class StringFunctions{
@Param VarBinaryHolder input;
@Output BigIntHolder out;
- public void setup(RecordBatch incoming){}
+ public void setup(RecordBatch incoming) {}
- public void eval(){
+ public void eval() {
out.value = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.getUTF8CharLength(input.buffer, input.start, input.end);
}
}
@@ -150,9 +149,9 @@ public class StringFunctions{
@Param VarCharHolder input;
@Output BigIntHolder out;
- public void setup(RecordBatch incoming){}
+ public void setup(RecordBatch incoming) {}
- public void eval(){
+ public void eval() {
out.value = input.end - input.start;
}
}
@@ -163,9 +162,9 @@ public class StringFunctions{
@Param VarCharHolder input;
@Output BigIntHolder out;
- public void setup(RecordBatch incoming){}
+ public void setup(RecordBatch incoming) {}
- public void eval(){
+ public void eval() {
out.value = (input.end - input.start) * 8;
}
}
@@ -186,9 +185,9 @@ public class StringFunctions{
@Output BigIntHolder out;
- public void setup(RecordBatch incoming){}
+ public void setup(RecordBatch incoming) {}
- public void eval(){
+ public void eval() {
//Do string match.
int pos = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.stringLeftMatchUTF8(str.buffer, str.start, str.end,
substr.buffer, substr.start, substr.end);
@@ -211,9 +210,9 @@ public class StringFunctions{
@Output BigIntHolder out;
- public void setup(RecordBatch incoming){}
+ public void setup(RecordBatch incoming) {}
- public void eval(){
+ public void eval() {
//Do string match.
int pos = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.stringLeftMatchUTF8(str.buffer, str.start, str.end,
substr.buffer, substr.start, substr.end);
@@ -237,10 +236,10 @@ public class StringFunctions{
@Output VarCharHolder out;
@Inject DrillBuf buffer;
- public void setup(RecordBatch incoming){
+ public void setup(RecordBatch incoming) {
}
- public void eval(){
+ public void eval() {
out.buffer = buffer = buffer.reallocIfNeeded(input.end- input.start);
out.start = 0;
out.end = input.end - input.start;
@@ -268,7 +267,7 @@ public class StringFunctions{
@Output VarCharHolder out;
@Inject DrillBuf buffer;
- public void setup(RecordBatch incoming){
+ public void setup(RecordBatch incoming) {
}
public void eval() {
@@ -380,7 +379,7 @@ public class StringFunctions{
@Output VarCharHolder out;
@Workspace ByteBuf buffer;
- public void setup(RecordBatch incoming){
+ public void setup(RecordBatch incoming) {
}
public void eval() {
@@ -415,7 +414,7 @@ public class StringFunctions{
@Output VarCharHolder out;
@Workspace ByteBuf buffer;
- public void setup(RecordBatch incoming){
+ public void setup(RecordBatch incoming) {
}
public void eval() {
@@ -457,7 +456,7 @@ public class StringFunctions{
@Output VarCharHolder out;
@Inject DrillBuf buffer;
- public void setup(RecordBatch incoming){
+ public void setup(RecordBatch incoming) {
}
public void eval() {
@@ -479,11 +478,11 @@ public class StringFunctions{
@Inject DrillBuf buffer;
@Output VarCharHolder out;
- public void setup(RecordBatch incoming){
+ public void setup(RecordBatch incoming) {
buffer = buffer.reallocIfNeeded(8000);
}
- public void eval(){
+ public void eval() {
out.buffer = buffer;
out.start = out.end = 0;
int fromL = from.end - from.start;
@@ -496,8 +495,9 @@ public class StringFunctions{
for (; i<=text.end - fromL; ) {
int j = from.start;
for (; j<from.end; j++) {
- if (text.buffer.getByte(i + j - from.start) != from.buffer.getByte(j))
+ if (text.buffer.getByte(i + j - from.start) != from.buffer.getByte(j)) {
break;
+ }
}
if (j == from.end ) {
@@ -544,7 +544,7 @@ public class StringFunctions{
@Output VarCharHolder out;
- public void setup(RecordBatch incoming){
+ public void setup(RecordBatch incoming) {
}
public void eval() {
@@ -579,8 +579,9 @@ public class StringFunctions{
while (count < length.value - textCharCount) {
for (id = fill.start; id < fill.end; id++) {
- if (count == length.value - textCharCount)
+ if (count == length.value - textCharCount) {
break;
+ }
currentByte = fill.buffer.getByte(id);
if (currentByte < 0x128 || // 1-byte char. First byte is 0xxxxxxx.
@@ -594,8 +595,9 @@ public class StringFunctions{
} // end of while
//copy "text" into "out"
- for (id = text.start; id < text.end; id++)
+ for (id = text.start; id < text.end; id++) {
out.buffer.setByte(out.end++, text.buffer.getByte(id));
+ }
}
} // end of eval
@@ -615,7 +617,7 @@ public class StringFunctions{
@Output VarCharHolder out;
- public void setup(RecordBatch incoming){
+ public void setup(RecordBatch incoming) {
}
public void eval() {
@@ -648,16 +650,18 @@ public class StringFunctions{
out.buffer = buffer;
out.start = out.end = 0;
- for (id = text.start; id < text.end; id++)
+ for (id = text.start; id < text.end; id++) {
out.buffer.setByte(out.end++, text.buffer.getByte(id));
+ }
//copy "fill" on right. Total # of char to copy : length.value - textCharCount
int count = 0;
while (count < length.value - textCharCount) {
for (id = fill.start; id < fill.end; id++) {
- if (count == length.value - textCharCount)
+ if (count == length.value - textCharCount) {
break;
+ }
currentByte = fill.buffer.getByte(id);
if (currentByte < 0x128 || // 1-byte char. First byte is 0xxxxxxx.
@@ -686,7 +690,7 @@ public class StringFunctions{
@Output VarCharHolder out;
- public void setup(RecordBatch incoming){
+ public void setup(RecordBatch incoming) {
}
public void eval() {
@@ -719,7 +723,7 @@ public class StringFunctions{
@Output VarCharHolder out;
- public void setup(RecordBatch incoming){
+ public void setup(RecordBatch incoming) {
}
public void eval() {
@@ -729,7 +733,9 @@ public class StringFunctions{
int bytePerChar = 0;
//Scan from right of "text", stop until find a char not in "from"
for (int id = text.end - 1; id >= text.start; id -= bytePerChar) {
- while ((text.buffer.getByte(id) & 0xC0) == 0x80 && id >= text.start) id--;
+ while ((text.buffer.getByte(id) & 0xC0) == 0x80 && id >= text.start) {
+ id--;
+ }
bytePerChar = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.utf8CharLen(text.buffer, id);
int pos = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.stringLeftMatchUTF8(from.buffer, from.start, from.end,
text.buffer, id, id + bytePerChar);
@@ -752,7 +758,7 @@ public class StringFunctions{
@Output VarCharHolder out;
- public void setup(RecordBatch incoming){
+ public void setup(RecordBatch incoming) {
}
public void eval() {
@@ -773,7 +779,9 @@ public class StringFunctions{
//Scan from right of "text", stop until find a char not in "from"
for (int id = text.end - 1; id >= text.start; id -= bytePerChar) {
- while ((text.buffer.getByte(id) & 0xC0) == 0x80 && id >= text.start) id--;
+ while ((text.buffer.getByte(id) & 0xC0) == 0x80 && id >= text.start) {
+ id--;
+ }
bytePerChar = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.utf8CharLen(text.buffer, id);
int pos = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.stringLeftMatchUTF8(from.buffer, from.start, from.end,
text.buffer, id, id + bytePerChar);
@@ -796,19 +804,21 @@ public class StringFunctions{
@Inject DrillBuf buffer;
- public void setup(RecordBatch incoming){
+ public void setup(RecordBatch incoming) {
}
- public void eval(){
+ public void eval() {
out.buffer = buffer = buffer.reallocIfNeeded( (left.end - left.start) + (right.end - right.start));
out.start = out.end = 0;
int id = 0;
- for (id = left.start; id < left.end; id++)
+ for (id = left.start; id < left.end; id++) {
out.buffer.setByte(out.end++, left.buffer.getByte(id));
+ }
- for (id = right.start; id < right.end; id++)
+ for (id = right.start; id < right.end; id++) {
out.buffer.setByte(out.end++, right.buffer.getByte(id));
+ }
}
}
@@ -822,20 +832,22 @@ public class StringFunctions{
@Inject DrillBuf buffer;
- public void setup(RecordBatch incoming){
+ public void setup(RecordBatch incoming) {
}
- public void eval(){
+ public void eval() {
out.buffer = buffer = buffer.reallocIfNeeded( (left.end - left.start) + (right.end - right.start));;
out.start = out.end = 0;
int id = 0;
- for (id = left.start; id < left.end; id++)
+ for (id = left.start; id < left.end; id++) {
out.buffer.setByte(out.end++, left.buffer.getByte(id));
+ }
if (right.isSet == 1) {
- for (id = right.start; id < right.end; id++)
- out.buffer.setByte(out.end++, right.buffer.getByte(id));
+ for (id = right.start; id < right.end; id++) {
+ out.buffer.setByte(out.end++, right.buffer.getByte(id));
+ }
}
}
}
@@ -849,21 +861,23 @@ public class StringFunctions{
@Inject DrillBuf buffer;
- public void setup(RecordBatch incoming){
+ public void setup(RecordBatch incoming) {
}
- public void eval(){
+ public void eval() {
out.buffer = buffer.reallocIfNeeded( (left.end - left.start) + (right.end - right.start));
out.start = out.end = 0;
int id = 0;
if (left.isSet == 1) {
- for (id = left.start; id < left.end; id++)
+ for (id = left.start; id < left.end; id++) {
out.buffer.setByte(out.end++, left.buffer.getByte(id));
+ }
}
- for (id = right.start; id < right.end; id++)
- out.buffer.setByte(out.end++, right.buffer.getByte(id));
+ for (id = right.start; id < right.end; id++) {
+ out.buffer.setByte(out.end++, right.buffer.getByte(id));
+ }
}
}
@@ -876,22 +890,24 @@ public class StringFunctions{
@Inject DrillBuf buffer;
- public void setup(RecordBatch incoming){
+ public void setup(RecordBatch incoming) {
}
- public void eval(){
+ public void eval() {
out.buffer = buffer.reallocIfNeeded( (left.end - left.start) + (right.end - right.start));
out.start = out.end = 0;
int id = 0;
if (left.isSet == 1) {
- for (id = left.start; id < left.end; id++)
+ for (id = left.start; id < left.end; id++) {
out.buffer.setByte(out.end++, left.buffer.getByte(id));
+ }
}
if (right.isSet == 1) {
- for (id = right.start; id < right.end; id++)
- out.buffer.setByte(out.end++, right.buffer.getByte(id));
+ for (id = right.start; id < right.end; id++) {
+ out.buffer.setByte(out.end++, right.buffer.getByte(id));
+ }
}
}
}
@@ -974,7 +990,7 @@ public class StringFunctions{
System.out.println(len + ":" + num);
out.start = 0;
out.buffer = buffer = buffer.reallocIfNeeded( len * num );
- for(int i =0; i < num; i++){
+ for (int i =0; i < num; i++) {
in.buffer.getBytes(in.start, out.buffer, i * len, len);
}
out.end = len * num;
@@ -1001,8 +1017,8 @@ public class StringFunctions{
public void eval() {
byte[] bytea = new byte[in.end - in.start];
int index =0;
- for(int i = in.start; i<in.end; i++, index++){
- bytea[index]=in.buffer.getByte(i);
+ for (int i = in.start; i<in.end; i++, index++) {
+ bytea[index]=in.buffer.getByte(i);
}
byte[] outBytea = new String(bytea, inCharset).getBytes(com.google.common.base.Charsets.UTF_8);
out.buffer = buffer = buffer.reallocIfNeeded(outBytea.length);
@@ -1035,10 +1051,10 @@ public class StringFunctions{
int index = in.end;
int innerindex = 0;
- for (int id = in.start; id < in.end; id+=charlen){
+ for (int id = in.start; id < in.end; id+=charlen) {
innerindex = charlen = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.utf8CharLen(in.buffer, id);
- while(innerindex > 0){
+ while (innerindex > 0) {
out.buffer.setByte(index - innerindex, in.buffer.getByte(id + (charlen - innerindex)));
innerindex-- ;
}
@@ -1047,4 +1063,5 @@ public class StringFunctions{
}
}
}
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/VarHelpers.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/VarHelpers.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/VarHelpers.java
index 75b5ecd..75fec81 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/VarHelpers.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/VarHelpers.java
@@ -67,8 +67,9 @@ public class VarHelpers {
public static final int compare(NullableVarBinaryHolder left, NullableVarBinaryHolder right) {
if (left.isSet == 0) {
- if (right.isSet == 0)
+ if (right.isSet == 0) {
return 0;
+ }
return -1;
} else if (right.isSet == 0) {
return 1;
@@ -95,8 +96,9 @@ public class VarHelpers {
public static final int compare(NullableVarBinaryHolder left, NullableVarCharHolder right) {
if (left.isSet == 0) {
- if (right.isSet == 0)
+ if (right.isSet == 0) {
return 0;
+ }
return -1;
} else if (right.isSet == 0) {
return 1;
@@ -123,8 +125,9 @@ public class VarHelpers {
public static final int compare(NullableVarCharHolder left, NullableVarCharHolder right) {
if (left.isSet == 0) {
- if (right.isSet == 0)
+ if (right.isSet == 0) {
return 0;
+ }
return -1;
} else if (right.isSet == 0) {
return 1;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/memory/Accountor.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/memory/Accountor.java b/exec/java-exec/src/main/java/org/apache/drill/exec/memory/Accountor.java
index 4df9646..d11f224 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/memory/Accountor.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/memory/Accountor.java
@@ -58,7 +58,7 @@ public class Accountor {
}
}
- public boolean transferTo(Accountor target, DrillBuf buf, long size){
+ public boolean transferTo(Accountor target, DrillBuf buf, long size) {
boolean withinLimit = target.forceAdditionalReservation(size);
release(buf, size);
@@ -89,18 +89,20 @@ public class Accountor {
}
public boolean forceAdditionalReservation(long size) {
- if(size > 0){
+ if (size > 0) {
return remainder.forceGet(size);
- }else{
+ } else {
return true;
}
}
- public void reserved(long expected, DrillBuf buf){
+ public void reserved(long expected, DrillBuf buf) {
// make sure to take away the additional memory that happened due to rounding.
long additional = buf.capacity() - expected;
- if(additional > 0) remainder.forceGet(additional);
+ if (additional > 0) {
+ remainder.forceGet(additional);
+ }
if (ENABLE_ACCOUNTING) {
buffers.put(buf, new DebugStackTrace(buf.capacity(), Thread.currentThread().getStackTrace()));
@@ -108,14 +110,16 @@ public class Accountor {
}
- public void releasePartial(DrillBuf buf, long size){
+ public void releasePartial(DrillBuf buf, long size) {
remainder.returnAllocation(size);
if (ENABLE_ACCOUNTING) {
- if(buf != null){
+ if (buf != null) {
DebugStackTrace dst = buffers.get(buf);
- if(dst == null) throw new IllegalStateException("Partially releasing a buffer that has already been released. Buffer: " + buf);
+ if (dst == null) {
+ throw new IllegalStateException("Partially releasing a buffer that has already been released. Buffer: " + buf);
+ }
dst.size -= size;
- if(dst.size < 0){
+ if (dst.size < 0) {
throw new IllegalStateException("Partially releasing a buffer that has already been released. Buffer: " + buf);
}
}
@@ -125,7 +129,9 @@ public class Accountor {
public void release(DrillBuf buf, long size) {
remainder.returnAllocation(size);
if (ENABLE_ACCOUNTING) {
- if(buf != null && buffers.remove(buf) == null) throw new IllegalStateException("Releasing a buffer that has already been released. Buffer: " + buf);
+ if (buf != null && buffers.remove(buf) == null) {
+ throw new IllegalStateException("Releasing a buffer that has already been released. Buffer: " + buf);
+ }
}
}
@@ -136,7 +142,7 @@ public class Accountor {
sb.append("Attempted to close accountor with ");
sb.append(buffers.size());
sb.append(" buffer(s) still allocated");
- if(handle != null){
+ if (handle != null) {
sb.append("for QueryId: ");
sb.append(QueryIdHelper.getQueryId(handle.getQueryId()));
sb.append(", MajorFragmentId: ");
@@ -146,7 +152,6 @@ public class Accountor {
}
sb.append(".\n");
-
Multimap<DebugStackTrace, DebugStackTrace> multi = LinkedListMultimap.create();
for (DebugStackTrace t : buffers.values()) {
multi.put(t, t);
@@ -158,7 +163,7 @@ public class Accountor {
sb.append("\n\n\tTotal ");
sb.append(allocs.size());
sb.append(" allocation(s) of byte size(s): ");
- for(DebugStackTrace alloc : allocs){
+ for (DebugStackTrace alloc : allocs) {
sb.append(alloc.size);
sb.append(", ");
}
@@ -167,13 +172,12 @@ public class Accountor {
entry.addToString(sb);
}
IllegalStateException e = new IllegalStateException(sb.toString());
- if(errorOnLeak){
+ if (errorOnLeak) {
throw e;
- }else{
+ } else {
logger.warn("Memory leaked.", e);
}
-
}
remainder.close();
@@ -210,15 +214,19 @@ public class Accountor {
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
DebugStackTrace other = (DebugStackTrace) obj;
- if (!Arrays.equals(elements, other.elements))
+ if (!Arrays.equals(elements, other.elements)) {
return false;
+ }
// weird equal where size doesn't matter for multimap purposes.
// if (size != other.size)
// return false;
@@ -226,4 +234,5 @@ public class Accountor {
}
}
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/memory/AtomicRemainder.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/memory/AtomicRemainder.java b/exec/java-exec/src/main/java/org/apache/drill/exec/memory/AtomicRemainder.java
index 83cd3b7..263caa0 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/memory/AtomicRemainder.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/memory/AtomicRemainder.java
@@ -64,11 +64,13 @@ public class AtomicRemainder {
* @param size
*/
public boolean forceGet(long size) {
- if(get(size)){
+ if (get(size)) {
return true;
- }else{
+ } else {
availableShared.addAndGet(size);
- if (parent != null) parent.forceGet(size);
+ if (parent != null) {
+ parent.forceGet(size);
+ }
return false;
}
}
@@ -160,17 +162,19 @@ public class AtomicRemainder {
logger.warn("Tried to close remainder, but it has already been closed", new Exception());
return;
}
- if (availablePrivate.get() != initPrivate || availableShared.get() != initShared){
+ if (availablePrivate.get() != initPrivate || availableShared.get() != initShared) {
IllegalStateException e = new IllegalStateException(
String
.format(ERROR, initPrivate, availablePrivate.get(), initPrivate - availablePrivate.get(), initShared, availableShared.get(), initShared - availableShared.get()));
- if(errorOnLeak){
+ if (errorOnLeak) {
throw e;
- }else{
+ } else {
logger.warn("Memory leaked during query.", e);
}
}
- if(parent != null) parent.returnAllocation(initPrivate);
+ if (parent != null) {
+ parent.returnAllocation(initPrivate);
+ }
closed = true;
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/memory/TopLevelAllocator.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/memory/TopLevelAllocator.java b/exec/java-exec/src/main/java/org/apache/drill/exec/memory/TopLevelAllocator.java
index 5a594aa..a8e8a28 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/memory/TopLevelAllocator.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/memory/TopLevelAllocator.java
@@ -53,7 +53,7 @@ public class TopLevelAllocator implements BufferAllocator {
this(maximumAllocation, true);
}
- private TopLevelAllocator(long maximumAllocation, boolean errorOnLeak){
+ private TopLevelAllocator(long maximumAllocation, boolean errorOnLeak) {
this.errorOnLeak = errorOnLeak;
this.acct = new Accountor(errorOnLeak, null, null, maximumAllocation, 0);
this.empty = DrillBuf.getEmpty(this, acct);
@@ -72,8 +72,12 @@ public class TopLevelAllocator implements BufferAllocator {
}
public DrillBuf buffer(int min, int max) {
- if(min == 0) return empty;
- if(!acct.reserve(min)) return null;
+ if (min == 0) {
+ return empty;
+ }
+ if(!acct.reserve(min)) {
+ return null;
+ }
UnsafeDirectLittleEndian buffer = innerAllocator.directBuffer(min, max);
DrillBuf wrapped = new DrillBuf(this, acct, buffer);
acct.reserved(min, wrapped);
@@ -97,12 +101,14 @@ public class TopLevelAllocator implements BufferAllocator {
@Override
public BufferAllocator getChildAllocator(FragmentHandle handle, long initialReservation, long maximumReservation) throws OutOfMemoryException {
- if(!acct.reserve(initialReservation)){
+ if(!acct.reserve(initialReservation)) {
throw new OutOfMemoryException(String.format("You attempted to create a new child allocator with initial reservation %d but only %d bytes of memory were available.", initialReservation, acct.getCapacity() - acct.getAllocation()));
};
logger.debug("New child allocator with initial reservation {}", initialReservation);
ChildAllocator allocator = new ChildAllocator(handle, acct, maximumReservation, initialReservation, childrenMap);
- if(ENABLE_ACCOUNTING) childrenMap.put(allocator, Thread.currentThread().getStackTrace());
+ if (ENABLE_ACCOUNTING) {
+ childrenMap.put(allocator, Thread.currentThread().getStackTrace());
+ }
return allocator;
}
@@ -158,8 +164,10 @@ public class TopLevelAllocator implements BufferAllocator {
@Override
public DrillBuf buffer(int size, int max) {
- if(size == 0) return empty;
- if(!childAcct.reserve(size)){
+ if (size == 0) {
+ return empty;
+ }
+ if(!childAcct.reserve(size)) {
logger.warn("Unable to allocate buffer of size {} due to memory limit. Current allocation: {}", size, getAllocatedMemory(), new Exception());
return null;
};
@@ -182,7 +190,7 @@ public class TopLevelAllocator implements BufferAllocator {
@Override
public BufferAllocator getChildAllocator(FragmentHandle handle, long initialReservation, long maximumReservation)
throws OutOfMemoryException {
- if(!childAcct.reserve(initialReservation)){
+ if (!childAcct.reserve(initialReservation)) {
throw new OutOfMemoryException(String.format("You attempted to create a new child allocator with initial reservation %d but only %d bytes of memory were available.", initialReservation, childAcct.getAvailable()));
};
logger.debug("New child allocator with initial reservation {}", initialReservation);
@@ -191,14 +199,16 @@ public class TopLevelAllocator implements BufferAllocator {
return newChildAllocator;
}
- public PreAllocator getNewPreAllocator(){
+ public PreAllocator getNewPreAllocator() {
return new PreAlloc(this, this.childAcct);
}
@Override
public void close() {
if (ENABLE_ACCOUNTING) {
- if(thisMap != null) thisMap.remove(this);
+ if (thisMap != null) {
+ thisMap.remove(this);
+ }
for (ChildAllocator child : children.keySet()) {
if (!child.isClosed()) {
StringBuilder sb = new StringBuilder();
@@ -213,9 +223,9 @@ public class TopLevelAllocator implements BufferAllocator {
IllegalStateException e = new IllegalStateException(String.format(
"Failure while trying to close child allocator: Child level allocators not closed. Fragment %d:%d. Stack trace: \n %s",
handle.getMajorFragmentId(), handle.getMinorFragmentId(), sb.toString()));
- if(errorOnLeak){
+ if (errorOnLeak) {
throw e;
- }else{
+ } else {
logger.warn("Memory leak.", e);
}
}
@@ -242,7 +252,7 @@ public class TopLevelAllocator implements BufferAllocator {
}
- public PreAllocator getNewPreAllocator(){
+ public PreAllocator getNewPreAllocator() {
return new PreAlloc(this, this.acct);
}
@@ -250,7 +260,7 @@ public class TopLevelAllocator implements BufferAllocator {
int bytes = 0;
final Accountor acct;
final BufferAllocator allocator;
- private PreAlloc(BufferAllocator allocator, Accountor acct){
+ private PreAlloc(BufferAllocator allocator, Accountor acct) {
this.acct = acct;
this.allocator = allocator;
}
@@ -258,9 +268,9 @@ public class TopLevelAllocator implements BufferAllocator {
/**
*
*/
- public boolean preAllocate(int bytes){
+ public boolean preAllocate(int bytes) {
- if(!acct.reserve(bytes)){
+ if (!acct.reserve(bytes)) {
return false;
}
this.bytes += bytes;
@@ -269,10 +279,11 @@ public class TopLevelAllocator implements BufferAllocator {
}
- public DrillBuf getAllocation(){
+ public DrillBuf getAllocation() {
DrillBuf b = new DrillBuf(allocator, acct, innerAllocator.directBuffer(bytes, bytes));
acct.reserved(bytes, b);
return b;
}
}
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/metrics/DrillMetrics.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/metrics/DrillMetrics.java b/exec/java-exec/src/main/java/org/apache/drill/exec/metrics/DrillMetrics.java
index d3bc93e..a9799b2 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/metrics/DrillMetrics.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/metrics/DrillMetrics.java
@@ -65,8 +65,9 @@ public class DrillMetrics {
reporter.start();
return reporter;
- } else
+ } else {
return null;
+ }
}
private static Slf4jReporter getLogReporter() {
@@ -76,8 +77,9 @@ public class DrillMetrics {
reporter.start(config.getInt(ExecConstants.METRICS_LOG_OUTPUT_INTERVAL), TimeUnit.SECONDS);
return reporter;
- } else
+ } else {
return null;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/ops/FragmentContext.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/ops/FragmentContext.java b/exec/java-exec/src/main/java/org/apache/drill/exec/ops/FragmentContext.java
index e54a967..a888ea7 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/ops/FragmentContext.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/ops/FragmentContext.java
@@ -93,15 +93,15 @@ public class FragmentContext implements Closeable {
this.rootFragmentTimeZone = fragment.getTimeZone();
logger.debug("Getting initial memory allocation of {}", fragment.getMemInitial());
logger.debug("Fragment max allocation: {}", fragment.getMemMax());
- try{
+ try {
OptionList list;
- if(!fragment.hasOptionsJson() || fragment.getOptionsJson().isEmpty()){
+ if (!fragment.hasOptionsJson() || fragment.getOptionsJson().isEmpty()) {
list = new OptionList();
- }else{
+ } else {
list = dbContext.getConfig().getMapper().readValue(fragment.getOptionsJson(), OptionList.class);
}
this.fragmentOptions = new FragmentOptionManager(context.getOptionManager(), list);
- }catch(Exception e){
+ } catch (Exception e) {
throw new ExecutionSetupException("Failure while reading plan options.", e);
}
this.allocator = context.getAllocator().getChildAllocator(fragment.getHandle(), fragment.getMemInitial(), fragment.getMemMax());
@@ -130,7 +130,7 @@ public class FragmentContext implements Closeable {
return context;
}
- public SchemaPlus getRootSchema(){
+ public SchemaPlus getRootSchema() {
if (connection == null) {
fail(new UnsupportedOperationException("Schema tree can only be created in root fragment. " +
"This is a non-root fragment."));
@@ -150,7 +150,7 @@ public class FragmentContext implements Closeable {
return context.getEndpoint();
}
- public FragmentStats getStats(){
+ public FragmentStats getStats() {
return this.stats;
}
@@ -254,12 +254,14 @@ public class FragmentContext implements Closeable {
@Override
public void close() {
- for(Thread thread: daemonThreads){
+ for (Thread thread: daemonThreads) {
thread.interrupt();
}
Object[] mbuffers = ((LongObjectOpenHashMap<Object>)(Object)managedBuffers).values;
- for(int i =0; i < mbuffers.length; i++){
- if(managedBuffers.allocated[i]) ((DrillBuf)mbuffers[i]).release();
+ for (int i =0; i < mbuffers.length; i++) {
+ if (managedBuffers.allocated[i]) {
+ ((DrillBuf)mbuffers[i]).release();
+ }
}
if (buffers != null) {
@@ -268,17 +270,19 @@ public class FragmentContext implements Closeable {
allocator.close();
}
- public DrillBuf replace(DrillBuf old, int newSize){
- if(managedBuffers.remove(old.memoryAddress()) == null) throw new IllegalStateException("Tried to remove unmanaged buffer.");
+ public DrillBuf replace(DrillBuf old, int newSize) {
+ if (managedBuffers.remove(old.memoryAddress()) == null) {
+ throw new IllegalStateException("Tried to remove unmanaged buffer.");
+ }
old.release();
return getManagedBuffer(newSize);
}
- public DrillBuf getManagedBuffer(){
+ public DrillBuf getManagedBuffer() {
return getManagedBuffer(256);
}
- public DrillBuf getManagedBuffer(int size){
+ public DrillBuf getManagedBuffer(int size) {
DrillBuf newBuf = allocator.buffer(size);
managedBuffers.put(newBuf.memoryAddress(), newBuf);
newBuf.setFragmentContext(this);
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/ops/OperatorContext.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/ops/OperatorContext.java b/exec/java-exec/src/main/java/org/apache/drill/exec/ops/OperatorContext.java
index c5dea4f..54edf88 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/ops/OperatorContext.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/ops/OperatorContext.java
@@ -51,32 +51,36 @@ public class OperatorContext implements Closeable {
this.stats = stats;
}
- public DrillBuf replace(DrillBuf old, int newSize){
- if(managedBuffers.remove(old.memoryAddress()) == null) throw new IllegalStateException("Tried to remove unmanaged buffer.");
+ public DrillBuf replace(DrillBuf old, int newSize) {
+ if (managedBuffers.remove(old.memoryAddress()) == null) {
+ throw new IllegalStateException("Tried to remove unmanaged buffer.");
+ }
old.release();
return getManagedBuffer(newSize);
}
- public DrillBuf getManagedBuffer(){
+ public DrillBuf getManagedBuffer() {
return getManagedBuffer(256);
}
- public DrillBuf getManagedBuffer(int size){
+ public DrillBuf getManagedBuffer(int size) {
DrillBuf newBuf = allocator.buffer(size);
managedBuffers.put(newBuf.memoryAddress(), newBuf);
newBuf.setOperatorContext(this);
return newBuf;
}
- public static int getChildCount(PhysicalOperator popConfig){
+ public static int getChildCount(PhysicalOperator popConfig) {
Iterator<PhysicalOperator> iter = popConfig.iterator();
int i = 0;
- while(iter.hasNext()){
+ while (iter.hasNext()) {
iter.next();
i++;
}
- if(i == 0) i = 1;
+ if (i == 0) {
+ i = 1;
+ }
return i;
}
@@ -101,8 +105,10 @@ public class OperatorContext implements Closeable {
// release managed buffers.
Object[] buffers = ((LongObjectOpenHashMap<Object>)(Object)managedBuffers).values;
- for(int i =0; i < buffers.length; i++){
- if(managedBuffers.allocated[i]) ((DrillBuf)buffers[i]).release();
+ for (int i =0; i < buffers.length; i++) {
+ if (managedBuffers.allocated[i]) {
+ ((DrillBuf)buffers[i]).release();
+ }
}
if (allocator != null) {
@@ -111,7 +117,8 @@ public class OperatorContext implements Closeable {
closed = true;
}
- public OperatorStats getStats(){
+ public OperatorStats getStats() {
return stats;
}
+
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/opt/BasicOptimizer.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/opt/BasicOptimizer.java b/exec/java-exec/src/main/java/org/apache/drill/exec/opt/BasicOptimizer.java
index b993d77..876ba37 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/opt/BasicOptimizer.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/opt/BasicOptimizer.java
@@ -228,7 +228,9 @@ public class BasicOptimizer extends Optimizer{
@Override
public PhysicalOperator visitScan(Scan scan, Object obj) throws OptimizerException {
StoragePluginConfig config = logicalPlan.getStorageEngineConfig(scan.getStorageEngine());
- if(config == null) throw new OptimizerException(String.format("Logical plan referenced the storage engine config %s but the logical plan didn't have that available as a config.", scan.getStorageEngine()));
+ if(config == null) {
+ throw new OptimizerException(String.format("Logical plan referenced the storage engine config %s but the logical plan didn't have that available as a config.", scan.getStorageEngine()));
+ }
StoragePlugin storagePlugin;
try {
storagePlugin = context.getStorage().getPlugin(config);
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/AbstractBase.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/AbstractBase.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/AbstractBase.java
index e54e67c..defb4e4 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/AbstractBase.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/AbstractBase.java
@@ -33,8 +33,10 @@ public abstract class AbstractBase implements PhysicalOperator{
@Override
public void accept(GraphVisitor<PhysicalOperator> visitor) {
visitor.enter(this);
- if(this.iterator() == null) throw new IllegalArgumentException("Null iterator for pop." + this);
- for(PhysicalOperator o : this){
+ if (this.iterator() == null) {
+ throw new IllegalArgumentException("Null iterator for pop." + this);
+ }
+ for (PhysicalOperator o : this) {
Preconditions.checkNotNull(o, String.format("Null in iterator for pop %s.", this));
o.accept(visitor);
}
@@ -46,7 +48,7 @@ public abstract class AbstractBase implements PhysicalOperator{
return true;
}
- public final void setOperatorId(int id){
+ public final void setOperatorId(int id) {
this.id = id;
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/AbstractPhysicalVisitor.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/AbstractPhysicalVisitor.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/AbstractPhysicalVisitor.java
index 9e7beec..48b3801 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/AbstractPhysicalVisitor.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/base/AbstractPhysicalVisitor.java
@@ -90,7 +90,7 @@ public abstract class AbstractPhysicalVisitor<T, X, E extends Throwable> impleme
@Override
public T visitHashAggregate(HashAggregate agg, X value) throws E {
- return visitOp(agg, value);
+ return visitOp(agg, value);
}
@Override
@@ -120,7 +120,7 @@ public abstract class AbstractPhysicalVisitor<T, X, E extends Throwable> impleme
public T visitChildren(PhysicalOperator op, X value) throws E{
- for(PhysicalOperator child : op){
+ for (PhysicalOperator child : op) {
child.accept(this, value);
}
return null;
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/676f5df6/exec/java-exec/src/main/java/org/apache/drill/exec/physical/config/Screen.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/config/Screen.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/config/Screen.java
index 5f0648d..980b413 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/config/Screen.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/config/Screen.java
@@ -60,7 +60,9 @@ public class Screen extends AbstractStore {
public void applyAssignments(List<DrillbitEndpoint> endpoints) throws PhysicalOperatorSetupException {
// we actually don't have to do anything since nothing should have changed. we'll check just check that things
// didn't get screwed up.
- if (endpoints.size() != 1) throw new PhysicalOperatorSetupException("A Screen operator can only be assigned to a single node.");
+ if (endpoints.size() != 1) {
+ throw new PhysicalOperatorSetupException("A Screen operator can only be assigned to a single node.");
+ }
DrillbitEndpoint endpoint = endpoints.iterator().next();
// logger.debug("Endpoint this: {}, assignment: {}", this.endpoint, endpoint);
if (!endpoint.equals(this.endpoint)) {