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
Showing
17 changed files
with
137 additions
and
384 deletions.
There are no files selected for viewing
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
84 changes: 84 additions & 0 deletions
84
presto-main/src/test/java/com/facebook/presto/operator/scalar/AbstractTestFunctions.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,84 @@ | ||
/* | ||
* 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.operator.scalar; | ||
|
||
import com.facebook.presto.metadata.FunctionListBuilder; | ||
import com.facebook.presto.metadata.Metadata; | ||
import com.facebook.presto.metadata.ParametricFunction; | ||
import com.facebook.presto.spi.ErrorCodeSupplier; | ||
import com.facebook.presto.spi.PrestoException; | ||
import com.facebook.presto.spi.type.Type; | ||
|
||
import java.util.List; | ||
|
||
import static com.facebook.presto.spi.StandardErrorCode.INVALID_CAST_ARGUMENT; | ||
import static com.facebook.presto.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT; | ||
import static com.facebook.presto.type.UnknownType.UNKNOWN; | ||
import static java.lang.String.format; | ||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.fail; | ||
|
||
public abstract class AbstractTestFunctions | ||
{ | ||
protected final FunctionAssertions functionAssertions = new FunctionAssertions(); | ||
|
||
protected void assertFunction(String projection, Type expectedType, Object expected) | ||
{ | ||
functionAssertions.assertFunction(projection, expectedType, expected); | ||
} | ||
|
||
protected void assertInvalidFunction(String projection, Type expectedType, String message) | ||
{ | ||
try { | ||
assertFunction(projection, expectedType, null); | ||
fail("Expected to throw an INVALID_FUNCTION_ARGUMENT exception with message " + message); | ||
} | ||
catch (PrestoException e) { | ||
assertEquals(e.getErrorCode(), INVALID_FUNCTION_ARGUMENT.toErrorCode()); | ||
assertEquals(e.getMessage(), message); | ||
} | ||
} | ||
|
||
protected void assertInvalidFunction(String projection, Type expectedType, ErrorCodeSupplier expectedErrorCode) | ||
{ | ||
try { | ||
assertFunction(projection, expectedType, null); | ||
fail(format("Expected to throw %s exception", expectedErrorCode.toErrorCode())); | ||
} | ||
catch (PrestoException e) { | ||
assertEquals(e.getErrorCode(), expectedErrorCode.toErrorCode()); | ||
} | ||
} | ||
|
||
protected void assertInvalidCast(String projection) | ||
{ | ||
try { | ||
// type isn't necessary as the function is not valid | ||
functionAssertions.assertFunction(projection, UNKNOWN, null); | ||
fail("Expected to throw an INVALID_CAST_ARGUMENT exception"); | ||
} | ||
catch (PrestoException e) { | ||
assertEquals(e.getErrorCode(), INVALID_CAST_ARGUMENT.toErrorCode()); | ||
} | ||
} | ||
|
||
protected void registerScalar(Class<?> clazz) | ||
{ | ||
Metadata metadata = functionAssertions.getMetadata(); | ||
List<ParametricFunction> functions = new FunctionListBuilder(metadata.getTypeManager()) | ||
.scalar(clazz) | ||
.getFunctions(); | ||
metadata.getFunctionRegistry().addFunctions(functions); | ||
} | ||
} |
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
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
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
Oops, something went wrong.