Skip to content

Commit

Permalink
add IntegerEnumType
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-ohayon committed Jun 22, 2020
1 parent b6f7986 commit fd40b7b
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed 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.
*/
package com.facebook.presto.common.type;

import java.util.Map;

public interface EnumType<T>
extends Type
{
Map<String, T> getEntries();

Type getValueType();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Licensed 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.
*/
package com.facebook.presto.common.type;

import com.facebook.presto.common.block.Block;
import com.facebook.presto.common.function.SqlFunctionProperties;

import java.util.Map;
import java.util.stream.Collectors;

public class IntegerEnumType
extends AbstractLongType
implements EnumType<Long>
{
private final Map<String, Long> entries;

public IntegerEnumType(String name, Map<String, Long> entries)
{
super(TypeSignature.parseTypeSignature(name));
this.entries = entries;
}

@Override
public Map<String, Long> getEntries()
{
return entries;
}

@Override
public Object getObjectValue(SqlFunctionProperties properties, Block block, int position)
{
if (block.isNull(position)) {
return null;
}

return block.getLong(position);
}

@Override
public boolean isComparable()
{
return false;
}

@Override
public boolean isOrderable()
{
return false;
}

@Override
public Type getValueType() {
return BigintType.BIGINT;
}
}

0 comments on commit fd40b7b

Please sign in to comment.