-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b6f7986
commit fd40b7b
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
presto-common/src/main/java/com/facebook/presto/common/type/EnumType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
66 changes: 66 additions & 0 deletions
66
presto-common/src/main/java/com/facebook/presto/common/type/IntegerEnumType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |