com.facebook.presto.spi.function.SqlType Java Examples

The following examples show how to use com.facebook.presto.spi.function.SqlType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BloomFilterPersistScalarFunction.java    From presto-bloomfilter with Apache License 2.0 6 votes vote down vote up
@SqlType(StandardTypes.BOOLEAN)
@Nullable
@SqlNullable
public static Boolean bloomFilterPersist(@SqlNullable @SqlType(BloomFilterType.TYPE) Slice bloomFilterSlice, @SqlType(StandardTypes.VARCHAR) Slice urlSlice) throws Exception
{
    // Nothing todo
    if (urlSlice == null) {
        return true;
    }
    BloomFilter bf = getOrLoadBloomFilter(bloomFilterSlice);

    // Persist
    // we do not try catch here to make sure that errors are communicated clearly to the client
    // and typical retry logic continues to work
    String url = new String(urlSlice.getBytes());
    if (!HTTP_CLIENT.isStarted()) {
        log.warn("Http client was not started, trying to start");
        HTTP_CLIENT.start();
    }
    Request post = HTTP_CLIENT.POST(url);
    post.content(new StringContentProvider(new String(bf.toBase64())));
    post.method("PUT");
    post.send();
    log.info("Persisted " + bf.toString() + " " + url);
    return true;
}
 
Example #2
Source File: MatchQueryFunction.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@ScalarFunction("match_phrase")
@Description("es match_phrase")
@SqlType(StandardTypes.VARCHAR)
@SqlNullable
public static Slice matchPhrase(
        @SqlType(StandardTypes.VARCHAR) Slice filter)
{
    if (filter == null) {
        return null;
    }
    String filterStr = filter.toStringUtf8();

    QueryBuilder builder = QueryBuilders.matchPhraseQuery(MATCH_COLUMN_SEP, filterStr);
    return Slices.utf8Slice(builder.toString());
}
 
Example #3
Source File: BloomFilterContainsScalarFunction.java    From presto-bloomfilter with Apache License 2.0 5 votes vote down vote up
@SqlType(StandardTypes.BOOLEAN)
@SqlNullable
public static Boolean varcharBloomFilterContains(@SqlNullable @SqlType(BloomFilterType.TYPE) Slice bloomFilterSlice, @SqlNullable @SqlType(StandardTypes.VARCHAR) Slice slice)
{
    BloomFilter bf = getOrLoadBloomFilter(bloomFilterSlice);
    if (slice == null) {
        return false;
    }
    return bf.mightContain(slice);
}
 
Example #4
Source File: BloomFilterFromString.java    From presto-bloomfilter with Apache License 2.0 5 votes vote down vote up
@InputFunction
public static void input(
        BloomFilterState state,
        @SqlType(VARCHAR) Slice slice)
{
    BloomFilter bf = getOrCreateBloomFilter(state, BloomFilter.DEFAULT_BLOOM_FILTER_EXPECTED_INSERTIONS, BloomFilter.DEFAULT_BLOOM_FILTER_FALSE_POSITIVE_PERCENTAGE);
    bf.putAll(BloomFilter.newInstance(slice.getBytes()));
    state.setBloomFilter(bf);
}
 
Example #5
Source File: BloomFilterLoad.java    From presto-bloomfilter with Apache License 2.0 5 votes vote down vote up
@InputFunction
public static void input(
        BloomFilterState state,
        @SqlType(VARCHAR) Slice slice) throws Exception
{
    BloomFilter bf = getOrCreateBloomFilter(state, BloomFilter.DEFAULT_BLOOM_FILTER_EXPECTED_INSERTIONS, BloomFilter.DEFAULT_BLOOM_FILTER_FALSE_POSITIVE_PERCENTAGE);
    // Do not try catch because we want to have visibility for client errors
    bf.putAll(BloomFilter.fromUrl(new String(slice.getBytes())));
    state.setBloomFilter(bf);
}
 
Example #6
Source File: BloomFilterAggregation.java    From presto-bloomfilter with Apache License 2.0 5 votes vote down vote up
@InputFunction
public static void input(
        BloomFilterState state,
        @SqlType(VARCHAR) Slice slice,
        @SqlType(StandardTypes.BIGINT) long expectedInsertions,
        @SqlType(StandardTypes.DOUBLE) double falsePositivePercentage)
{
    BloomFilter bf = getOrCreateBloomFilter(state, (int) expectedInsertions, falsePositivePercentage);
    // Note: do not update the memory size as this is constant to our bloom filter implementation
    bf.put(slice);
}
 
Example #7
Source File: BloomFilterAggregation.java    From presto-bloomfilter with Apache License 2.0 5 votes vote down vote up
@InputFunction
public static void input(
        BloomFilterState state,
        @SqlType(VARCHAR) Slice slice,
        @SqlType(StandardTypes.BIGINT) long expectedInsertions)
{
    BloomFilter bf = getOrCreateBloomFilter(state, (int) expectedInsertions, BloomFilter.DEFAULT_BLOOM_FILTER_FALSE_POSITIVE_PERCENTAGE);
    // Note: do not update the memory size as this is constant to our bloom filter implementation
    bf.put(slice);
}
 
Example #8
Source File: BloomFilterAggregation.java    From presto-bloomfilter with Apache License 2.0 5 votes vote down vote up
@InputFunction
public static void input(
        BloomFilterState state,
        @SqlType(VARCHAR) Slice slice)
{
    BloomFilter bf = getOrCreateBloomFilter(state, BloomFilter.DEFAULT_BLOOM_FILTER_EXPECTED_INSERTIONS, BloomFilter.DEFAULT_BLOOM_FILTER_FALSE_POSITIVE_PERCENTAGE);
    // Note: do not update the memory size as this is constant to our bloom filter implementation
    bf.put(slice);
}
 
Example #9
Source File: BloomFilterToStringScalarFunction.java    From presto-bloomfilter with Apache License 2.0 5 votes vote down vote up
@Nullable
@SqlNullable
@SqlType(StandardTypes.VARCHAR)
public static Slice bloomFilterToString(@SqlNullable @SqlType(BloomFilterType.TYPE) Slice bloomFilterSlice)
{
    BloomFilter bf = getOrLoadBloomFilter(bloomFilterSlice);
    return Slices.wrappedBuffer(bf.toBase64());
}
 
Example #10
Source File: BloomFilterGetFalsePositivePercentageScalarFunction.java    From presto-bloomfilter with Apache License 2.0 5 votes vote down vote up
@Description(value = "Display expected insertions from the bloom filter")
@Nullable
@SqlNullable
@SqlType(StandardTypes.DOUBLE)
public static Double bloomFilterFalsePositivePercentage(@SqlNullable @SqlType(BloomFilterType.TYPE) Slice bloomFilterSlice)
{
    BloomFilter bf = getOrLoadBloomFilter(bloomFilterSlice);
    return bf.getFalsePositivePercentage();
}
 
Example #11
Source File: BloomFilterGetExpectedInsertionsScalarFunction.java    From presto-bloomfilter with Apache License 2.0 5 votes vote down vote up
@SqlType(StandardTypes.BIGINT)
@Nullable
@SqlNullable
public static Long bloomFilterExpectedInsertions(@SqlNullable @SqlType(BloomFilterType.TYPE) Slice bloomFilterSlice)
{
    BloomFilter bf = getOrLoadBloomFilter(bloomFilterSlice);
    return (long) bf.getExpectedInsertions();
}
 
Example #12
Source File: EthereumUDFs.java    From presto-ethereum with Apache License 2.0 5 votes vote down vote up
@ScalarFunction("toWei")
@Description("toWei")
@SqlType(StandardTypes.DOUBLE)
public static double toWei(@SqlType(StandardTypes.DOUBLE) double num, @SqlType(StandardTypes.VARCHAR) Slice unit) {
    String unitStr = unit.toStringUtf8().toUpperCase();
    EthereumUnit u = EthereumUnit.valueOf(unitStr);
    return u.toWei(num);
}
 
Example #13
Source File: EthereumUDFs.java    From presto-ethereum with Apache License 2.0 5 votes vote down vote up
@ScalarFunction("fromWei")
@Description("fromWei")
@SqlType(StandardTypes.DOUBLE)
public static double fromWei(@SqlType(StandardTypes.DOUBLE) double num, @SqlType(StandardTypes.VARCHAR) Slice unit) {
    String unitStr = unit.toStringUtf8().toUpperCase();
    EthereumUnit u = EthereumUnit.valueOf(unitStr);
    return u.fromWei(num);
}
 
Example #14
Source File: MatchQueryFunction.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@ScalarFunction("match_phrase")
@Description("es match_phrase")
@SqlType(StandardTypes.VARCHAR)
@SqlNullable
public static Slice matchPhrase(
        @SqlType(StandardTypes.VARCHAR) Slice filter)
{
    if (filter == null) {
        return null;
    }
    String filterStr = filter.toStringUtf8();

    QueryBuilder builder = QueryBuilders.matchPhraseQuery(MATCH_COLUMN_SEP, filterStr);
    return Slices.utf8Slice(builder.toString());
}
 
Example #15
Source File: MatchQueryFunction.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@ScalarFunction("match_query")
@Description("es match_query")
@SqlType(StandardTypes.VARCHAR)
@SqlNullable
public static Slice matchQuery(
        @SqlType(StandardTypes.VARCHAR) Slice filter)
{
    if (filter == null) {
        return null;
    }
    String filterStr = filter.toStringUtf8();

    QueryBuilder builder = QueryBuilders.matchQuery(MATCH_COLUMN_SEP, filterStr);
    return Slices.utf8Slice(builder.toString());
}
 
Example #16
Source File: MatchQueryFunction.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@ScalarFunction("match_phrase")
@Description("es match_phrase")
@SqlType(StandardTypes.VARCHAR)
@SqlNullable
public static Slice matchPhrase(
        @SqlType(StandardTypes.VARCHAR) Slice filter)
{
    if (filter == null) {
        return null;
    }
    String filterStr = filter.toStringUtf8();

    QueryBuilder builder = QueryBuilders.matchPhraseQuery(MATCH_COLUMN_SEP, filterStr);
    return Slices.utf8Slice(builder.toString());
}
 
Example #17
Source File: MatchQueryFunction.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@ScalarFunction("match_query")
@Description("es match_query")
@SqlType(StandardTypes.VARCHAR)
@SqlNullable
public static Slice matchQuery(
        @SqlType(StandardTypes.VARCHAR) Slice filter)
{
    if (filter == null) {
        return null;
    }
    String filterStr = filter.toStringUtf8();

    QueryBuilder builder = QueryBuilders.matchQuery(MATCH_COLUMN_SEP, filterStr);
    return Slices.utf8Slice(builder.toString());
}
 
Example #18
Source File: MatchQueryFunction.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@ScalarFunction("match_query")
@Description("es match_query")
@SqlType(StandardTypes.VARCHAR)
@SqlNullable
public static Slice matchQuery(
        @SqlType(StandardTypes.VARCHAR) Slice filter)
{
    if (filter == null) {
        return null;
    }
    String filterStr = filter.toStringUtf8();

    QueryBuilder builder = QueryBuilders.matchQuery(MATCH_COLUMN_SEP, filterStr);
    return Slices.utf8Slice(builder.toString());
}
 
Example #19
Source File: EthereumUDFs.java    From presto-ethereum with Apache License 2.0 4 votes vote down vote up
@ScalarFunction("eth_getTransactionCount")
@Description("Returns the number of transactions from this address")
@SqlType(StandardTypes.BIGINT)
public static long ethGetTransactionCount(@SqlType(StandardTypes.VARCHAR) Slice address, @SqlType(StandardTypes.VARCHAR) Slice blockName) throws IOException {
    return web3j.ethGetTransactionCount(address.toStringUtf8(), DefaultBlockParameter.valueOf(blockName.toStringUtf8())).send().getTransactionCount().longValue();
}
 
Example #20
Source File: EthereumUDFs.java    From presto-ethereum with Apache License 2.0 4 votes vote down vote up
@ScalarFunction("eth_getTransactionCount")
@Description("Returns the number of transactions from this address")
@SqlType(StandardTypes.BIGINT)
public static long ethGetTransactionCount(@SqlType(StandardTypes.VARCHAR) Slice address, @SqlType(StandardTypes.BIGINT) long blockNumber) throws IOException {
    return web3j.ethGetTransactionCount(address.toStringUtf8(), DefaultBlockParameter.valueOf(BigInteger.valueOf(blockNumber))).send().getTransactionCount().longValue();
}
 
Example #21
Source File: EthereumUDFs.java    From presto-ethereum with Apache License 2.0 4 votes vote down vote up
@ScalarFunction("eth_getTransactionCount")
@Description("Returns the number of transactions from this address")
@SqlType(StandardTypes.BIGINT)
public static long ethGetTransactionCount(@SqlType(StandardTypes.VARCHAR) Slice address) throws IOException {
    return web3j.ethGetTransactionCount(address.toStringUtf8(), DefaultBlockParameter.valueOf(LATEST)).send().getTransactionCount().longValue();
}
 
Example #22
Source File: EthereumUDFs.java    From presto-ethereum with Apache License 2.0 4 votes vote down vote up
@ScalarFunction("isContract")
@Description("isContract")
@SqlType(StandardTypes.BOOLEAN)
public static boolean isContract(@SqlType(StandardTypes.VARCHAR) Slice address) throws IOException {
    return !web3j.ethGetCode(address.toStringUtf8(), DefaultBlockParameter.valueOf(LATEST)).send().getCode().equals(ZERO_X);
}
 
Example #23
Source File: EthereumUDFs.java    From presto-ethereum with Apache License 2.0 4 votes vote down vote up
@ScalarFunction("eth_getBalance")
@Description("Returns the balance of an address")
@SqlType(StandardTypes.DOUBLE)
public static double ethGetBalance(@SqlType(StandardTypes.VARCHAR) Slice address, @SqlType(StandardTypes.VARCHAR) Slice blockName) throws IOException {
    return web3j.ethGetBalance(address.toStringUtf8(), DefaultBlockParameter.valueOf(blockName.toStringUtf8())).send().getBalance().doubleValue();
}
 
Example #24
Source File: EthereumUDFs.java    From presto-ethereum with Apache License 2.0 4 votes vote down vote up
@ScalarFunction("eth_getBalance")
@Description("Returns the balance of an address")
@SqlType(StandardTypes.DOUBLE)
public static double ethGetBalance(@SqlType(StandardTypes.VARCHAR) Slice address, @SqlType(StandardTypes.BIGINT) long blockNumber) throws IOException {
    return web3j.ethGetBalance(address.toStringUtf8(), DefaultBlockParameter.valueOf(BigInteger.valueOf(blockNumber))).send().getBalance().doubleValue();
}
 
Example #25
Source File: EthereumUDFs.java    From presto-ethereum with Apache License 2.0 4 votes vote down vote up
@ScalarFunction("eth_getBalance")
@Description("Returns the balance of an address")
@SqlType(StandardTypes.DOUBLE)
public static double ethGetBalance(@SqlType(StandardTypes.VARCHAR) Slice address) throws IOException {
    return web3j.ethGetBalance(address.toStringUtf8(), DefaultBlockParameter.valueOf(LATEST)).send().getBalance().doubleValue();
}
 
Example #26
Source File: EthereumUDFs.java    From presto-ethereum with Apache License 2.0 4 votes vote down vote up
@ScalarFunction("eth_blockNumber")
@Description("Returns current block number")
@SqlType(StandardTypes.BIGINT)
public static long ethBlockNumber() throws IOException {
    return web3j.ethBlockNumber().send().getBlockNumber().longValue();
}
 
Example #27
Source File: EthereumUDFs.java    From presto-ethereum with Apache License 2.0 4 votes vote down vote up
@ScalarFunction("eth_gasPrice")
@Description("Returns current gas price")
@SqlType(StandardTypes.DOUBLE)
public static double ethGasPrice() throws IOException {
    return web3j.ethGasPrice().send().getGasPrice().doubleValue();
}