Exemplo n.º 1
0
  /**
   * Create an initialize a {@link LazyObject} with the given bytes for the given fieldID.
   *
   * @param fieldID field for which the object is to be created
   * @param bytes value with which the object is to be initialized with
   * @return initialized {@link LazyObject}
   */
  public LazyObject<? extends ObjectInspector> toLazyObject(int fieldID, byte[] bytes) {
    ObjectInspector fieldOI = oi.getAllStructFieldRefs().get(fieldID).getFieldObjectInspector();

    LazyObject<? extends ObjectInspector> lazyObject = LazyFactory.createLazyObject(fieldOI);

    ByteArrayRef ref = new ByteArrayRef();

    ref.setData(bytes);

    // initialize the lazy object
    lazyObject.init(ref, 0, ref.getData().length);

    return lazyObject;
  }
Exemplo n.º 2
0
  @Override
  protected LazyObjectBase createLazyField(final int fieldID, final StructField fieldRef)
      throws SerDeException {
    if (columnsMapping[fieldID].hbaseRowKey) {
      return keyFactory.createKey(fieldRef.getFieldObjectInspector());
    }
    if (columnsMapping[fieldID].hbaseTimestamp) {
      return LazyFactory.createLazyObject(fieldRef.getFieldObjectInspector());
    }

    if (valueFactories != null) {
      return valueFactories.get(fieldID).createValueObject(fieldRef.getFieldObjectInspector());
    }

    // fallback to default
    return HBaseSerDeHelper.createLazyField(
        columnsMapping, fieldID, fieldRef.getFieldObjectInspector());
  }
Exemplo n.º 3
0
  @Override
  public void initialize(final Configuration conf, final Properties tbl) throws SerDeException {

    LOG.debug("Entry SdbSerDe::initialize");

    final String columnString = tbl.getProperty(ConfigurationUtil.COLUMN_MAPPING);
    if (StringUtils.isBlank(columnString)) {
      throw new SerDeException("No column mapping found, use " + ConfigurationUtil.COLUMN_MAPPING);
    }
    final String[] columnNamesArray = ConfigurationUtil.getAllColumns(columnString);
    fieldCount = columnNamesArray.length;
    columnNames = new ArrayList<String>(columnNamesArray.length);
    columnNames.addAll(Arrays.asList(columnNamesArray));

    serdeParams = LazySimpleSerDe.initSerdeParams(conf, tbl, getClass().getName());

    LOG.debug(
        "EscapeChar:"
            + serdeParams.getEscapeChar()
            + "getSeparators:"
            + new String(serdeParams.getSeparators()));

    byte[] sparator = new byte[1];
    sparator[0] = '|';
    objectInspector =
        LazyFactory.createLazyStructInspector(
            serdeParams.getColumnNames(),
            serdeParams.getColumnTypes(),
            sparator,
            serdeParams.getNullSequence(),
            serdeParams.isLastColumnTakesRest(),
            serdeParams.isEscaped(),
            serdeParams.getEscapeChar());

    row = new LazyStruct((LazySimpleStructObjectInspector) objectInspector);

    LOG.debug("Exit SdbSerDe::initialize");
  }