Java Code Examples for org.apache.avro.io.parsing.Symbol#SkipAction

The following examples show how to use org.apache.avro.io.parsing.Symbol#SkipAction . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FastDeserializerGeneratorBase.java    From avro-util with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected FieldAction seekFieldAction(boolean shouldReadCurrent, Schema.Field field,
    ListIterator<Symbol> symbolIterator) {

  Schema.Type type = field.schema().getType();

  if (!shouldReadCurrent) {
    return FieldAction.fromValues(type, false, EMPTY_SYMBOL);
  }

  boolean shouldRead = true;
  Symbol fieldSymbol = END_SYMBOL;

  if (Schema.Type.RECORD.equals(type)) {
    if (symbolIterator.hasNext()) {
      fieldSymbol = symbolIterator.next();
      if (fieldSymbol instanceof Symbol.SkipAction) {
        return FieldAction.fromValues(type, false, fieldSymbol);
      } else {
        symbolIterator.previous();
      }
    }
    return FieldAction.fromValues(type, true, symbolIterator);
  }

  while (symbolIterator.hasNext()) {
    Symbol symbol = symbolIterator.next();

    if (symbol instanceof Symbol.ErrorAction) {
      throw new FastDeserializerGeneratorException(((Symbol.ErrorAction) symbol).msg);
    }

    if (symbol instanceof Symbol.SkipAction) {
      shouldRead = false;
      fieldSymbol = symbol;
      break;
    }

    if (symbol instanceof Symbol.WriterUnionAction) {
      if (symbolIterator.hasNext()) {
        symbol = symbolIterator.next();

        if (symbol instanceof Symbol.Alternative) {
          shouldRead = true;
          fieldSymbol = symbol;
          break;
        }
      }
    }

    if (symbol.kind == Symbol.Kind.TERMINAL) {
      shouldRead = true;
      if (symbolIterator.hasNext()) {
        symbol = symbolIterator.next();

        if (symbol instanceof Symbol.Repeater) {
          fieldSymbol = symbol;
        } else {
          fieldSymbol = symbolIterator.previous();
        }
      } else if (!symbolIterator.hasNext() && getSymbolPrintName(symbol) != null) {
        fieldSymbol = symbol;
      }
      break;
    }
  }

  return FieldAction.fromValues(type, shouldRead, fieldSymbol);
}
 
Example 2
Source File: FastDeserializerGeneratorBase.java    From avro-fastserde with Apache License 2.0 4 votes vote down vote up
protected FieldAction seekFieldAction(boolean shouldReadCurrent, Schema.Field field,
        ListIterator<Symbol> symbolIterator) {

    Schema.Type type = field.schema().getType();

    if (!shouldReadCurrent) {
        return FieldAction.fromValues(type, false, EMPTY_SYMBOL);
    }

    boolean shouldRead = true;
    Symbol fieldSymbol = END_SYMBOL;

    if (Schema.Type.RECORD.equals(type)) {
        if (symbolIterator.hasNext()) {
            fieldSymbol = symbolIterator.next();
            if (fieldSymbol instanceof Symbol.SkipAction) {
                return FieldAction.fromValues(type, false, fieldSymbol);
            } else {
                symbolIterator.previous();
            }
        }
        return FieldAction.fromValues(type, true, symbolIterator);
    }

    while (symbolIterator.hasNext()) {
        Symbol symbol = symbolIterator.next();

        if (symbol instanceof Symbol.ErrorAction) {
            throw new FastDeserializerGeneratorException(((Symbol.ErrorAction) symbol).msg);
        }

        if (symbol instanceof Symbol.SkipAction) {
            shouldRead = false;
            fieldSymbol = symbol;
            break;
        }

        if (symbol instanceof Symbol.WriterUnionAction) {
            if (symbolIterator.hasNext()) {
                symbol = symbolIterator.next();

                if (symbol instanceof Symbol.Alternative) {
                    shouldRead = true;
                    fieldSymbol = symbol;
                    break;
                }
            }
        }

        if (symbol.kind == Symbol.Kind.TERMINAL) {
            shouldRead = true;
            if (symbolIterator.hasNext()) {
                symbol = symbolIterator.next();

                if (symbol instanceof Symbol.Repeater) {
                    fieldSymbol = symbol;
                } else {
                    fieldSymbol = symbolIterator.previous();
                }
            } else if (!symbolIterator.hasNext() && getSymbolPrintName(symbol) != null) {
                fieldSymbol = symbol;
            }
            break;
        }
    }

    return FieldAction.fromValues(type, shouldRead, fieldSymbol);
}