/** * A Directive can include number ranges like start:end=value[,start:end=value]*. This * visitor method allows you to collect all the number ranges and create a token type * <code>Ranges</code>. */ @Override public RecipeSymbol.Builder visitNumberRanges(DirectivesParser.NumberRangesContext ctx) { List<Triplet<Numeric, Numeric,String>> output = new ArrayList<>(); List<DirectivesParser.NumberRangeContext> ranges = ctx.numberRange(); for(DirectivesParser.NumberRangeContext range : ranges) { List<TerminalNode> numbers = range.Number(); String text = range.value().getText(); if (text.startsWith("'") && text.endsWith("'")) { text = text.substring(1, text.length() - 1); } Triplet<Numeric, Numeric, String> val = new Triplet<>(new Numeric(new LazyNumber(numbers.get(0).getText())), new Numeric(new LazyNumber(numbers.get(1).getText())), text ); output.add(val); } builder.addToken(new Ranges(output)); return builder; }
@Override public void initialize(Arguments args) throws DirectiveParseException { this.col1 = ((ColumnName) args.value("source")).value(); this.col2 = ((ColumnName) args.value("destination")).value(); List<Triplet<Numeric, Numeric, String>> ranges = ((Ranges) args.value("ranges")).value(); for (Triplet<Numeric, Numeric, String> range : ranges) { double lower = range.getFirst().value().doubleValue(); double upper = range.getSecond().value().doubleValue(); rangeMap.put(Range.closed(lower, upper), range.getThird()); } }
@Override public void initialize(Arguments args) throws DirectiveParseException { this.col = ((ColumnName) args.value("source")).value(); this.start = ((Numeric) args.value("start")).value().intValue(); this.end = ((Numeric) args.value("end")).value().intValue(); this.dest = ((ColumnName) args.value("destination")).value(); this.start = this.start - 1; this.end = this.end - 1; }
@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 { this.col = ((ColumnName) args.value("column")).value(); List<LazyNumber> numbers = ((NumericList) args.value("width")).value(); this.widths = new int[numbers.size()]; int idx = 0; int sum = 0; while (idx < numbers.size()) { this.widths[idx] = numbers.get(idx).intValue(); sum += this.widths[idx]; idx = idx + 1; } this.recordLength = sum; if(args.contains("padding")) { this.padding = ((Text) args.value("padding")).value(); } else { this.padding = null; } }
/** * This visitor methods extracts the list of numeric specified. It creates a token * type <code>NumericList</code> to be added to <code>TokenGroup</code>. */ @Override public RecipeSymbol.Builder visitNumberList(DirectivesParser.NumberListContext ctx) { List<TerminalNode> numbers = ctx.Number(); List<LazyNumber> numerics = new ArrayList<>(); for (TerminalNode number : numbers) { numerics.add(new LazyNumber(number.getText())); } builder.addToken(new NumericList(numerics)); return builder; }
@Override public void initialize(Arguments args) throws DirectiveParseException { this.column = ((ColumnName) args.value("column")).value(); if (args.contains("depth")) { this.depth = ((Numeric) args.value("depth")).value().intValue(); } else { this.depth = Integer.MAX_VALUE; } }
/** * A Directive can consist of numeric field. This visitor method extracts the * numeric value <code>Numeric</code>. */ @Override public RecipeSymbol.Builder visitNumber(DirectivesParser.NumberContext ctx) { LazyNumber number = new LazyNumber(ctx.Number().getText()); builder.addToken(new Numeric(number)); return builder; }
@Override public void initialize(Arguments args) throws DirectiveParseException { this.col = ((ColumnName) args.value("column")).value(); if (args.contains("depth")) { this.depth = ((Numeric) args.value("depth")).value().intValue(); } else { this.depth = Integer.MAX_VALUE; } }
/** * 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(); 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 { column = ((ColumnName) args.value("column")).value(); delimiter = ((Text) args.value("delimiter")).value(); if (args.contains("limit")) { Numeric numeric = args.value("limit"); limit = numeric.value().intValue(); } else { limit = Integer.MAX_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.recordName = ((Text) args.value("record-name")).value(); 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.column = ((ColumnName) args.value("column")).value(); if (args.contains("depth")) { this.depth = ((Numeric) args.value("depth")).value().intValue(); } else { this.depth = Integer.MAX_VALUE; } context = new DefaultHapiContext(); context.setValidationContext(new NoValidation()); ModelClassFactory modelClassFactory = new GenericModelClassFactory(); parser = new PipeParser(modelClassFactory); parser.getParserConfiguration().setAllowUnknownVersions(true); }