@Override public OutputRow setValues(final InputRow row) { for (int i = 0; i < _columns.length; i++) { final Object value = row.getValue(_columns[i]); _values[i] = value; } return this; }
@Override public Number[] transform(final InputRow inputRow) { final long id; if (IdType.ROW_NUMBER == idType) { id = inputRow.getId(); } else { id = _counter.incrementAndGet(); } return new Number[] { id }; }
public void run(InputRow row, int count) { final String group; if (groupColumn == null) { group = GROUP_NAME_SINGLE; } else { group = row.getValue(groupColumn); } final FillPatternsBuilder fillPatternsBuilder = getOrCreateFillPatternsBuilder(group); final List<Object> inspectedValues = row.getValues(inspectedColumns); final List<Object> inspectionOutcomes = new ArrayList<>(inspectionTypes.length); for (int i = 0; i < inspectionTypes.length; i++) { final Object value = inspectedValues.get(i); final InspectionType inspectionType = inspectionTypes[i]; inspectionOutcomes.add(inspectionType.inspect(value)); } fillPatternsBuilder.addObservation(row, inspectionOutcomes); }
Object key = row.getValue(groupKey); if (key == null) { if (skipNullGroupKeys) { final long rowId = row.getId(); final Object value = row.getValue(aggregatedValues[i]); final AggregateBuilder<?> aggregateBuilder = aggregateBuilders.get(i + 1); if (aggregateBuilder instanceof AbstractRowNumberAwareAggregateBuilder) {
@Override public String evaluate(final InputRow row) { final SimpleContext context = new SimpleContext(); final List<InputColumn<?>> inputColumns = row.getInputColumns(); for (final InputColumn<?> inputColumn : inputColumns) { if (!(inputColumn instanceof ExpressionBasedInputColumn)) { final Object value = row.getValue(inputColumn); final Class<?> javaType = inputColumn.getDataType(); final ValueExpression valueExpression = _factory.createValueExpression(value, javaType); String variableName = inputColumn.getName(); variableName = StringUtils.replaceWhitespaces(variableName, "_"); context.setVariable(variableName, valueExpression); } } try { final ValueExpression valueExpression = _factory.createValueExpression(context, _expression, String.class); return (String) valueExpression.getValue(context); } catch (final ELException e) { logger.error("Could not evaluate EL expression", e); return null; } }
@Override public void run(final InputRow row, final int distinctCount) { final List<Object> result = row.getValues(columns); rows.add(result.toArray(new Object[result.size()])); }
@Override public List<InputColumn<?>> getInputColumns() { final List<InputColumn<?>> inputColumns = _delegate.getInputColumns(); inputColumns.addAll(_values.keySet()); return inputColumns; }
public void run(InputRow row, int count) { final String group; if (groupColumn == null) { group = GROUP_NAME_SINGLE; } else { group = row.getValue(groupColumn); } final FillPatternsBuilder fillPatternsBuilder = getOrCreateFillPatternsBuilder(group); final List<Object> inspectedValues = row.getValues(inspectedColumns); final List<Object> inspectionOutcomes = new ArrayList<>(inspectionTypes.length); for (int i = 0; i < inspectionTypes.length; i++) { final Object value = inspectedValues.get(i); final InspectionType inspectionType = inspectionTypes[i]; inspectionOutcomes.add(inspectionType.inspect(value)); } fillPatternsBuilder.addObservation(row, inspectionOutcomes); }
@Override public Object[] transform(final InputRow parentInputRow) { final MockInputRow wrappedInputRow = new MockInputRow(parentInputRow.getId()); final Set<Entry<InputColumn<?>, InputColumn<?>>> conversionEntries = _inputColumnConversion.entrySet(); for (final Entry<InputColumn<?>, InputColumn<?>> conversionEntry : conversionEntries) { final InputColumn<?> parentColumn = conversionEntry.getKey(); final Object value = parentInputRow.getValue(parentColumn); final InputColumn<?> wrappedColumn = conversionEntry.getValue(); wrappedInputRow.put(wrappedColumn, value); } final List<InputRow> outputRows = _consumeRowHandler.consumeRow(wrappedInputRow).getRows(); for (final InputRow wrappedOutputRow : outputRows) { final Object[] outputValues = convertToOutputValues(wrappedOutputRow); _outputRowCollector.putValues(outputValues); } return null; }
/** * Creates a string with all variable names replaced with dynamic values * coming from the {@link InputRow}'s values. * * @param str * the string to prepare with variables * @param inputRow * the input row containing the dynamic values to insert into the * string * @return */ protected String applyVariablesToString(final String str, final InputRow inputRow) { if (Strings.isNullOrEmpty(str)) { return null; } String result = str; final List<Object> values = inputRow.getValues(input); for (int i = 0; i < input.length; i++) { final Object value = values.get(i); final String valueStr; if (value == null) { valueStr = ""; } else { valueStr = value.toString(); } result = StringUtils.replaceAll(result, variableNames[i], valueStr); } return result; }
public List<InputColumn<?>> getInputColumns() { if (_inputColumns == null) { final List<InputRow> rows = getSampleRows(); if (!rows.isEmpty()) { final InputRow firstRow = rows.iterator().next(); final List<InputColumn<?>> inputColumns = firstRow.getInputColumns(); _inputColumns = CollectionUtils.filter(inputColumns, col -> { if (col instanceof MutableInputColumn) { if (((MutableInputColumn<?>) col).isHidden()) { // avoid hidden columns in the return false; } } return true; }); } else { _inputColumns = new ArrayList<>(0); } } return _inputColumns; }
private NullCheckCategory categorizeAnyFieldMode(final InputRow inputRow) { for (final InputColumn<?> col : columns) { final Object value = inputRow.getValue(col); if (value == null) { return NullCheckCategory.NULL; } if (considerEmptyStringAsNull && "".equals(value)) { return NullCheckCategory.NULL; } } return NullCheckCategory.NOT_NULL; }
@Override public void run(final InputRow row, final int distinctCount) { _rowCount.addAndGet(distinctCount); boolean allInvalid = true; for (int i = 0; i < _valueColumns.length; i++) { final Object value = row.getValue(_valueColumns[i]); final boolean valid = _conditions[i].isValid(value); if (_evaluationMode == EvaluationMode.ANY_FIELD && !valid) { _annotationFactory.annotate(row, distinctCount, _invalidRecords); if (_incompleteRowCollector != null) { _incompleteRowCollector.putValues(row.getValues(_outputDataStreamColumns).toArray()); } return; } if (valid) { allInvalid = false; } } if (_evaluationMode == EvaluationMode.ALL_FIELDS && allInvalid) { _annotationFactory.annotate(row, distinctCount, _invalidRecords); if (_incompleteRowCollector != null) { _incompleteRowCollector.putValues(row.getValues(_outputDataStreamColumns).toArray()); } return; } if (_completeRowCollector != null) { _completeRowCollector.putValues(row.getValues(_outputDataStreamColumns).toArray()); } }
private long getNextVirtualRowId(final InputRow row, final int recordNo) { if (_idGenerator == null) { // this can more or less never happen, except in test cases or in // cases where the consumers are programmatically being used outside // of an AnalysisRunner. There's a risk then here that we get the // same row ID twice, but that's life :-P final long offset = Long.MAX_VALUE; final long hiLoIntervalOffset = row.getId() * 10000; return offset - hiLoIntervalOffset + recordNo; } return _idGenerator.nextVirtualRowId(); }
@Override public Object[] transform(final InputRow inputRow) { final Object[] result = new Object[_initializedUnits.length]; for (int i = 0; i < _initializedUnits.length; i++) { final CoalesceUnit unit = _initializedUnits[i]; final InputColumn<?>[] inputColumns = unit.getInputColumns(); final List<Object> values = inputRow.getValues(inputColumns); final Object value = _coalesceFunction.coalesce(values); result[i] = value; } if (logger.isDebugEnabled()) { logger.debug("Coalesced values for row {}: {}", inputRow.getId(), Arrays.toString(result)); } return result; } }
@Override public void run(final InputRow inputRow) { final Object[] output = new Object[_initializedUnits.length]; for (int i = 0; i < _initializedUnits.length; i++) { final CoalesceUnit unit = _initializedUnits[i]; final InputColumn<?>[] inputColumns = unit.getInputColumns(); final List<Object> values = inputRow.getValues(inputColumns); final Object value = _coalesceFunction.coalesce(values); output[i] = value; } if (logger.isDebugEnabled()) { logger.debug("Fused values for row: {}", Arrays.toString(output)); } _outputRowCollector.putValues(output); }
@Override public String[] transform(final InputRow inputRow) { final String name = inputRow.getValue(nameColumn); final int randomIndex = random.nextInt(greetings.length); final String greeting = greetings[randomIndex]; final String greetingLine = greeting + " " + name; return new String[] { greetingLine }; }
/** * Constructs a {@link TransformedInputRow} based on another row and a row * ID. * * @param delegate * @param rowId */ public TransformedInputRow(final InputRow delegate, final Number rowId) { if (delegate == null) { throw new IllegalArgumentException("Delegate cannot be null"); } _delegate = delegate; if (rowId == null) { _id = delegate.getId(); } else { _id = rowId.longValue(); } _values = new LinkedHashMap<>(); }
@Override public RangeFilterCategory categorize(final InputRow inputRow) { final String value = inputRow.getValue(column); if (value == null) { return RangeFilterCategory.LOWER; } final int length = value.length(); if (length < minimumLength) { return RangeFilterCategory.LOWER; } if (length > maximumLength) { return RangeFilterCategory.HIGHER; } return RangeFilterCategory.VALID; }