Skip to content

Commit

Permalink
Cleanup cardinality() implementation for map
Browse files Browse the repository at this point in the history
  • Loading branch information
haozhun committed May 4, 2015
1 parent df4c826 commit c5229ed
Showing 1 changed file with 11 additions and 4 deletions.
Expand Up @@ -55,7 +55,7 @@ public boolean isHidden()
@Override
public boolean isDeterministic()
{
return false;
return true;
}

@Override
Expand All @@ -70,11 +70,18 @@ public FunctionInfo specialize(Map<String, Type> types, int arity, TypeManager t
checkArgument(arity == 1, "Cardinality expects only one argument");
Type keyType = types.get("K");
Type valueType = types.get("V");
return new FunctionInfo(new Signature("cardinality", parseTypeSignature(StandardTypes.BIGINT), parameterizedTypeName("map", keyType.getTypeSignature(), valueType.getTypeSignature())), "Returns the cardinality (size) of the map", false, METHOD_HANDLE, true, true, ImmutableList.of(false));
return new FunctionInfo(
new Signature("cardinality", parseTypeSignature(StandardTypes.BIGINT), parameterizedTypeName("map", keyType.getTypeSignature(), valueType.getTypeSignature())),
"Returns the cardinality (size) of the map",
isHidden(),
METHOD_HANDLE,
isDeterministic(),
false,
ImmutableList.of(false));
}

public static Long mapCardinality(Slice slice)
public static long mapCardinality(Slice slice)
{
return (long) readStructuralBlock(slice).getPositionCount() / 2;
return readStructuralBlock(slice).getPositionCount() / 2;
}
}

0 comments on commit c5229ed

Please sign in to comment.