/** * A Directive can consist of text field. These type of fields are enclosed within * a single-quote or a double-quote. This visitor method extracts the string value * within the quotes and creates a token type <code>Text</code>. */ @Override public RecipeSymbol.Builder visitText(DirectivesParser.TextContext ctx) { String value = ctx.String().getText(); builder.addToken(new Text(value.substring(1, value.length()-1))); return builder; }
@Override public void initialize(Arguments args) throws DirectiveParseException { sed = ((Text) args.value("sed-expression")).value(); }
@Override public void initialize(Arguments args) throws DirectiveParseException { this.column = ((ColumnName) args.value("column")).value(); String format = ((Text) args.value("format")).value(); this.formatter = new SimpleDateFormat(format); formatter.setTimeZone(TimeZone.getTimeZone("UTC")); }
/** * A Directive can include properties (which are a collection of key and value pairs), * this method extracts that token that is being identified as token of type <code>Properties</code>. */ @Override public RecipeSymbol.Builder visitPropertyList(DirectivesParser.PropertyListContext ctx) { Map<String, Token> props = new HashMap<>(); List<DirectivesParser.PropertyContext> properties = ctx.property(); for(DirectivesParser.PropertyContext property : properties) { String identifier = property.Identifier().getText(); Token token; if (property.number() != null) { token = new Numeric(new LazyNumber(property.number().getText())); } else if (property.bool() != null) { token = new Bool(Boolean.valueOf(property.bool().getText())); } else { String text = property.text().getText(); token = new Text(text.substring(1, text.length()-1)); } props.put(identifier, token); } builder.addToken(new Properties(props)); return builder; }
@Override public void initialize(Arguments args) throws DirectiveParseException { this.column = ((ColumnName) args.value("column")).value(); String type = ((Text) args.value("method")).value(); type = type.toUpperCase(); if (!type.equals("BASE64") && !type.equals("BASE32") && !type.equals("HEX")) { throw new DirectiveParseException( String.format("Type of decoding specified '%s' is not supported. Supports base64, base32 & hex.", type) ); } this.method = Method.valueOf(type); }
@Override public void initialize(Arguments args) throws DirectiveParseException { this.column = ((ColumnName) args.value("column")).value(); String value = ((Text) args.value("method")).value(); value = value.toUpperCase(); if (!value.equals("BASE64") && !value.equals("BASE32") && !value.equals("HEX")) { throw new DirectiveParseException( String.format("Type of encoding specified '%s' is not supported. Supports base64, base32 & hex.", value) ); } this.method = Method.valueOf(value); }
@Override public void initialize(Arguments args) throws DirectiveParseException { this.column = ((ColumnName) args.value("column")).value(); this.regex = ((Text) args.value("regex")).value(); pattern = Pattern.compile(regex); }
@Override public void initialize(Arguments args) throws DirectiveParseException { this.column = ((ColumnName) args.value("column")).value(); this.format = ((Text) args.value("format")).value(); this.destinationFmt = DateTimeFormatter.ofPattern(this.format); }
@Override public void initialize(Arguments args) throws DirectiveParseException { this.column = ((ColumnName) args.value("column")).value(); if (args.contains("timezone")) { this.timezone = TimeZone.getTimeZone(((Text) args.value("timezone")).value()); } else { this.timezone = TimeZone.getTimeZone("UTC"); } }
@Override public void initialize(Arguments args) throws DirectiveParseException { this.columns = ((ColumnNameList) args.value("column")).value(); this.pattern = ((Text) args.value("pattern")).value(); }
@Override public void initialize(Arguments args) throws DirectiveParseException { column = ((ColumnName) args.value("column")).value(); regex = ((Text) args.value("regex")).value(); }
@Override public void initialize(Arguments args) throws DirectiveParseException { this.column = ((ColumnName) args.value("column")).value(); this.mask = ((Text) args.value("mask")).value(); }
@Override public void initialize(Arguments args) throws DirectiveParseException { column = ((ColumnName) args.value("column")).value(); regex = ((Text) args.value("regex")).value(); }
@Override public void initialize(Arguments args) throws DirectiveParseException { this.column = ((ColumnName) args.value("column")).value(); this.value = ((Text) args.value("value")).value(); if (value != null && value.isEmpty()) { throw new DirectiveParseException( "Fixed value cannot be a empty string" ); } }
@Override public void initialize(Arguments args) throws DirectiveParseException { this.column = ((ColumnName) args.value("column")).value(); this.table = ((Text) args.value("table")).value(); this.initialized = false; }
@Override public void initialize(Arguments args) throws DirectiveParseException { this.column = ((ColumnName) args.value("column")).value(); this.charset = ((Text) args.value("charset")).value(); }
@Override public void initialize(Arguments args) throws DirectiveParseException { String matchType = ((Identifier) args.value("match-type")).value(); if (matchType.equalsIgnoreCase("if-matched")) { matched = true; } else if (matchType.equalsIgnoreCase("if-not-matched")) { matched = false; } else { throw new DirectiveParseException("Match type specified is not 'if-matched' or 'if-not-matched'"); } column = ((ColumnName) args.value("column")).value(); String regex = ((Text) args.value("regex")).value(); if (!regex.equalsIgnoreCase("null") && !regex.isEmpty()) { pattern = Pattern.compile(regex); } else { pattern = null; } }
@Override public void initialize(Arguments args) throws DirectiveParseException { gson = new Gson(); this.url = ((Text) args.value("url")).value(); this.columns = ((ColumnNameList) args.value("column")).value(); String hdrs = null; if (args.contains("header")) { hdrs = ((Text) args.value("header")).value();
@Override public void initialize(Arguments args) throws DirectiveParseException { this.column = ((ColumnName) args.value("column")).value(); String type = ((Text) args.value("catalog")).value(); if (!type.equalsIgnoreCase("ICD-9") && !type.equalsIgnoreCase("ICD-10-2016") && !type.equalsIgnoreCase("ICD-10-2017")) { throw new DirectiveParseException("Invalid ICD type - should be 9 (ICD-9) or 10 (ICD-10-2016 " + "or ICD-10-2017)."); } else { catalog = new ICDCatalog(type.toLowerCase()); if (!catalog.configure()) { throw new DirectiveParseException( String.format("Failed to configure ICD StaticCatalog. Check with your administrator") ); } } this.name = catalog.getCatalog().replaceAll("-", "_"); }
@Override public void initialize(Arguments args) throws DirectiveParseException { columnArg = args.value("col"); char delimiter = ','; if (args.contains("delimiter")) { delimiterArg = args.value("delimiter"); delimiter = delimiterArg.value().charAt(0); if (delimiterArg.value().startsWith("\\")) { String unescapedStr = StringEscapeUtils.unescapeJava(delimiterArg.value()); if (unescapedStr == null) { throw new DirectiveParseException("Invalid delimiter for CSV Parser: " + delimiterArg.value()); } delimiter = unescapedStr.charAt(0); } } this.format = CSVFormat.DEFAULT.withDelimiter(delimiter); this.format.withIgnoreEmptyLines(true) .withAllowMissingColumnNames(true) .withIgnoreSurroundingSpaces(true) .withRecordSeparator('\n'); this.hasHeader = false; if(args.contains("header")) { headerArg = args.value("header"); this.hasHeader = headerArg.value(); } }