-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add logging for errors/warnings with ksqldb's provided log libs * add two new udfs to convert emojis to aliases or codepoints * externalize test samples into json files read using MethodSource * refactor tests to use externalized test samples * doc update/pre-format fix + version bump
- Loading branch information
Showing
23 changed files
with
1,148 additions
and
169 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
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
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
57 changes: 57 additions & 0 deletions
57
src/main/java/com/github/hpgrahsl/ksqldb/functions/UdfEmojisToAliases.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,57 @@ | ||
/* | ||
* Copyright (c) 2020. Hans-Peter Grahsl ([email protected]) | ||
* | ||
* Licensed under the MIT License (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at: https://opensource.org/licenses/MIT | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS | ||
* OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
package com.github.hpgrahsl.ksqldb.functions; | ||
|
||
import com.vdurmont.emoji.EmojiParser; | ||
import io.confluent.ksql.function.udf.Udf; | ||
import io.confluent.ksql.function.udf.UdfDescription; | ||
import io.confluent.ksql.function.udf.UdfParameter; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@UdfDescription( | ||
name = "emojis_to_aliases", | ||
description = "leverages the emoji-java library to replace emojis contained in a string by their textual aliases", | ||
author = "Hans-Peter Grahsl (follow @hpgrahsl)", | ||
version = "1.0.0" | ||
) | ||
public class UdfEmojisToAliases { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(UdfEmojisToAliases.class); | ||
|
||
@Udf(description = "replace emojis contained in a string by their textual aliases") | ||
public String replaceEmojisWithAliases( | ||
@UdfParameter(value = "text", description = "the given text in which to replace any(!) emojis by their textual aliases") | ||
final String text, | ||
@UdfParameter(value = "fpAction",description = "how to deal with Fitzpatrick modifiers, must be either PARSE, REMOVE or IGNORE") | ||
final String fpAction) { | ||
|
||
if(text == null || fpAction == null) { | ||
LOGGER.warn("any of the UDF parameters ('text','fpAction') was null which is probably not intended"); | ||
return null; | ||
} | ||
|
||
try { | ||
return EmojiParser.parseToAliases(text, EmojiParser.FitzpatrickAction.valueOf(fpAction.toUpperCase())); | ||
} catch(IllegalArgumentException e) { | ||
LOGGER.error("the UDF parameter (fpAction '"+fpAction+"') is invalid", e); | ||
return null; | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.