private static TimeUnit getTimeUnit(String unitValue) throws DirectiveParseException { TimeUnit unit; try { unit = TimeUnit.valueOf(unitValue.toUpperCase()); } catch (IllegalArgumentException e) { throw new DirectiveParseException(String.format("'%s' is not a supported time unit. Supported time " + "units are %s", unitValue, SUPPORTED_TIME_UNITS)); } if (!SUPPORTED_TIME_UNITS.contains(unit)) { throw new DirectiveParseException(String.format("'%s' is not a supported time unit. Supported time " + "units are %s", unitValue, SUPPORTED_TIME_UNITS)); } return unit; }
public static String getNextToken(StringTokenizer tokenizer, String delimiter, String directive, String field, int lineno, boolean optional) throws DirectiveParseException { String value = null; if (tokenizer.hasMoreTokens()) { if (delimiter == null) { value = tokenizer.nextToken().trim(); } else { value = tokenizer.nextToken(delimiter).trim(); } } else { if (!optional) { throw new DirectiveParseException( String.format("Missing field '%s' at line number %d for directive <%s>.", field, lineno, directive) ); } } return value; } }
public static String getNextToken(StringTokenizer tokenizer, String delimiter, String directive, String field, int lineno, boolean optional) throws DirectiveParseException { String value = null; if (tokenizer.hasMoreTokens()) { if (delimiter == null) { value = tokenizer.nextToken().trim(); } else { value = tokenizer.nextToken(delimiter).trim(); } } else { if (!optional) { String usage = usageRegistry.getUsage(directive); throw new DirectiveParseException( String.format("Missing field '%s' at line number %d for directive <%s> (usage: %s)", field, lineno, directive, usage) ); } } return value; }
@Override public void initialize(Arguments args) throws DirectiveParseException { this.column = ((ColumnName) args.value("column")).value(); try { this.writer = CSVFormat.DEFAULT.print(new StringWriter()); } catch (IOException e) { throw new DirectiveParseException(toString() + " : " + "Unable to create CSV writer. " + e.getMessage()); } }
@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 { Expression expression = args.value("condition"); if(expression.value().isEmpty()) { throw new DirectiveParseException( String.format("No condition has been specified.") ); } condition = expression.value(); try { el.compile(condition); } catch (ELException e) { throw new DirectiveParseException(e.getMessage()); } }
@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("-", "_"); }
String[] components = header.split("="); if (components.length != 2) { throw new DirectiveParseException ( String.format("Incorrect header '%s' specified. " + "Header should be specified as 'key=value' pairs separated by a comma (,).", header) String value = components[1].trim(); if (key.isEmpty()) { throw new DirectiveParseException( String.format("Key specified for header '%s' cannot be empty.", header) ); throw new DirectiveParseException( String.format("Value specified for header '%s' cannot be empty.", header) );
@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 { 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 { this.column = ((ColumnName) args.value("column")).value(); Text algorithm = args.value("algorithm"); if (!MessageHash.isValid(algorithm.value())) { throw new DirectiveParseException( String.format("Algorithm '%s' specified in directive '%s' at line %d is not supported", algorithm, NAME, args.line()) ); } try { this.digest = MessageDigest.getInstance(algorithm.value()); } catch (NoSuchAlgorithmException e) { throw new DirectiveParseException( String.format("Unable to find algorithm specified '%s' in directive '%s' at line %d.", algorithm, NAME, args.line()) ); } this.encode = false; if(args.contains("encode")) { this.encode = ((Bool) args.value("encode")).value(); } }
@Override public void initialize(Arguments args) throws DirectiveParseException { this.column = ((ColumnName) args.value("column")).value(); this.schemaId = ((Identifier) args.value("schema-id")).value(); this.type = ((Identifier) args.value("encode-type")).value(); if (!"json".equalsIgnoreCase(type) && !"binary".equalsIgnoreCase(type)) { throw new DirectiveParseException( String.format("Parsing AVRO can be either of type 'json' or 'binary'") ); } if(args.contains("version")) { this.version = ((Numeric) args.value("version")).value().intValue(); } else { this.version = -1; } }
@Override public void initialize(Arguments args) throws DirectiveParseException { this.variable = ((Identifier) args.value("variable")).value(); this.expression = ((Expression) args.value("condition")).value(); try { el.compile(expression); } catch (ELException e) { throw new DirectiveParseException(e.getMessage()); } }
@Override public void initialize(Arguments args) throws DirectiveParseException { this.column = ((ColumnName) args.value("column")).value(); this.expression = ((Expression) args.value("expression")).value(); try { el.compile(expression); } catch (ELException e ){ throw new DirectiveParseException(e.getMessage()); } }
@Override public void initialize(Arguments args) throws DirectiveParseException { isTrue = true; if (args.contains("type")) { isTrue = ((Bool) args.value("type")).value(); } condition = ((Expression) args.value("condition")).value(); try { el.compile(condition); } catch (ELException e) { throw new DirectiveParseException(e.getMessage()); } }
@Override public void initialize(Arguments args) throws DirectiveParseException { condition = ((Expression) args.value("condition")).value(); try { el.compile(condition); } catch (ELException e) { throw new DirectiveParseException( String.format("Invalid condition '%s'.", condition) ); } if (args.contains("metric")) { metric = ((Identifier) args.value("metric")).value(); } if (args.contains("message")) { message = ((Text) args.value("message")).value(); } }
@Override public void initialize(Arguments args) throws DirectiveParseException { condition = ((Expression) args.value("condition")).value(); try { el.compile(condition); } catch (ELException e) { throw new DirectiveParseException( String.format("Invalid condition '%s'.", condition) ); } if (args.contains("metric")) { metric = ((Identifier) args.value("metric")).value(); } if (args.contains("message")) { message = ((Text) args.value("message")).value(); } }
@Override public void initialize(Arguments args) throws DirectiveParseException { this.variable = ((Identifier) args.value("variable")).value(); this.expression = ((Expression) args.value("condition")).value(); this.incrementBy = ((Numeric) args.value("value")).value().longValue(); try { el.compile(expression); } catch (ELException e) { throw new DirectiveParseException(e.getMessage()); } }
@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(); } }