Package org.apache.avro.util

Examples of org.apache.avro.util.Utf8


    case ENUM:
      return s.getEnumOrdinal(o.toString());
    case NULL:
      return 0;
    case STRING:
      return (o instanceof Utf8 ? o : new Utf8(o.toString())).hashCode();
    default:
      return o.hashCode();
    }
  }
View Full Code Here


        ? compare(o1, o2, s.getTypes().get(i1), equals)
        : i1 - i2;
    case NULL:
      return 0;
    case STRING:
      Utf8 u1 = o1 instanceof Utf8 ? (Utf8)o1 : new Utf8(o1.toString());
      Utf8 u2 = o2 instanceof Utf8 ? (Utf8)o2 : new Utf8(o2.toString());
      return u1.compareTo(u2);
    default:
      return ((Comparable)o1).compareTo(o2);
    }
  }
View Full Code Here

        // Some CharSequence subclasses are mutable, so we still need to make
        // a copy
        else if (value instanceof Utf8) {
          // Utf8 copy constructor is more efficient than converting
          // to string and then back to Utf8
          return new Utf8((Utf8)value);
        }
        return new Utf8(value.toString());
      case UNION:
        return deepCopy(
            schema.getTypes().get(resolveUnion(schema, value)), value);
      default:
        throw new AvroRuntimeException(
View Full Code Here

  }

  @Override
  public Utf8 readString(Utf8 old) throws IOException {
    int length = readInt();
    Utf8 result = (old != null ? old : new Utf8());
    result.setByteLength(length);
    if (0 != length) {
      doReadBytes(result.getBytes(), 0, length);
    }
    return result;
  }
View Full Code Here

  }

  /** Called to create a string from a default value.  Subclasses may override
   * to use a different string representation.  By default, this calls {@link
   * Utf8#Utf8(String)}.*/
  protected Object createString(String value) { return new Utf8(value); }
View Full Code Here

    case ENUM:
      return s.getEnumOrdinal(o.toString());
    case NULL:
      return 0;
    case STRING:
      return (o instanceof Utf8 ? o : new Utf8(o.toString())).hashCode();
    default:
      return o.hashCode();
    }
  }
View Full Code Here

    @Override
    public Map<Utf8, Object> map(Map<String, T> input) {
      Map<Utf8, Object> out = Maps.newHashMap();
      for (Map.Entry<String, T> e : input.entrySet()) {
        out.put(new Utf8(e.getKey()), mapFn.map(e.getValue()));
      }
      return out;
    }
View Full Code Here

    public Map<CharSequence, CharSequence> asAvroOptions()
    {
        Map<CharSequence, CharSequence> options = new HashMap<CharSequence, CharSequence>();
        for (Map.Entry<String, String> entry : otherOptions.entrySet())
            options.put(new Utf8(entry.getKey()), new Utf8(entry.getValue()));

        if (sstableCompressor == null)
            return options;

        options.put(new Utf8(SSTABLE_COMPRESSION), new Utf8(sstableCompressor.getClass().getName()));
        if (chunkLength != null)
            options.put(new Utf8(CHUNK_LENGTH), new Utf8(chunkLength.toString()));
        return options;
    }
View Full Code Here

    }
       
    public org.apache.cassandra.db.migration.avro.KsDef toAvro()
    {
        org.apache.cassandra.db.migration.avro.KsDef ks = new org.apache.cassandra.db.migration.avro.KsDef();
        ks.name = new Utf8(name);
        ks.strategy_class = new Utf8(strategyClass.getName());
        if (strategyOptions != null)
        {
            ks.strategy_options = new HashMap<CharSequence, CharSequence>();
            for (Map.Entry<String, String> e : strategyOptions.entrySet())
            {
                ks.strategy_options.put(new Utf8(e.getKey()), new Utf8(e.getValue()));
            }
        }
        ks.cf_defs = SerDeUtils.createArray(cfMetaData.size(), org.apache.cassandra.db.migration.avro.CfDef.SCHEMA$);
        for (CFMetaData cfm : cfMetaData.values())
            ks.cf_defs.add(cfm.toAvro());
View Full Code Here

    // converts CFM to avro CfDef
    public org.apache.cassandra.db.migration.avro.CfDef toAvro()
    {
        org.apache.cassandra.db.migration.avro.CfDef cf = new org.apache.cassandra.db.migration.avro.CfDef();
        cf.id = cfId;
        cf.keyspace = new Utf8(ksName);
        cf.name = new Utf8(cfName);
        cf.column_type = new Utf8(cfType.name());
        cf.comparator_type = new Utf8(comparator.toString());
        if (subcolumnComparator != null)
        {
            assert cfType == ColumnFamilyType.Super
                   : String.format("%s CF %s should not have subcomparator %s defined", cfType, cfName, subcolumnComparator);
            cf.subcomparator_type = new Utf8(subcolumnComparator.toString());
        }
        cf.comment = new Utf8(enforceCommentNotNull(comment));
        cf.row_cache_size = rowCacheSize;
        cf.key_cache_size = keyCacheSize;
        cf.read_repair_chance = readRepairChance;
        cf.replicate_on_write = replicateOnWrite;
        cf.gc_grace_seconds = gcGraceSeconds;
        cf.default_validation_class = defaultValidator == null ? null : new Utf8(defaultValidator.toString());
        cf.key_validation_class = new Utf8(keyValidator.toString());
        cf.min_compaction_threshold = minCompactionThreshold;
        cf.max_compaction_threshold = maxCompactionThreshold;
        cf.row_cache_save_period_in_seconds = rowCacheSavePeriodInSeconds;
        cf.key_cache_save_period_in_seconds = keyCacheSavePeriodInSeconds;
        cf.row_cache_keys_to_save = rowCacheKeysToSave;
        cf.merge_shards_chance = mergeShardsChance;
        cf.key_alias = keyAlias;
        cf.column_metadata = new ArrayList<ColumnDef>(column_metadata.size());
        for (ColumnDefinition cd : column_metadata.values())
            cf.column_metadata.add(cd.toAvro());
        cf.row_cache_provider = new Utf8(rowCacheProvider.getClass().getName());
        cf.compaction_strategy = new Utf8(compactionStrategyClass.getName());
        if (compactionStrategyOptions != null)
        {
            cf.compaction_strategy_options = new HashMap<CharSequence, CharSequence>();
            for (Map.Entry<String, String> e : compactionStrategyOptions.entrySet())
                cf.compaction_strategy_options.put(new Utf8(e.getKey()), new Utf8(e.getValue()));
        }
        cf.compression_options = compressionParameters.asAvroOptions();
        return cf;
    }
View Full Code Here

TOP

Related Classes of org.apache.avro.util.Utf8

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.