All Downloads are FREE. Search and download functionalities are using the official Maven repository.

co.cask.cdap.dq.rowkey.AggregationsRowKey Maven / Gradle / Ivy

/*
 * Copyright © 2015 Cask Data, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package co.cask.cdap.dq.rowkey;

import co.cask.cdap.api.common.Bytes;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
 * Class for constructing tableRowKeys that consist of the byte[] representation of "Aggregations"
 * concatenated with sourceID and then timestamp.
 */
public class AggregationsRowKey {
  private byte[] tableRowKey;
  private final byte[] prefixBytes = Bytes.toBytes("a"); // stands for "aggregations"

  public AggregationsRowKey(long timestamp, String sourceID) throws IOException {
    byte[] sourceIDBytes = Bytes.toBytes(sourceID);
    byte[] timestampBytes = Bytes.toBytes(timestamp);

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    outputStream.write(prefixBytes);
    outputStream.write(sourceIDBytes);
    outputStream.write(timestampBytes);

    tableRowKey = outputStream.toByteArray();
  }

  public byte[] getTableRowKey() {
    return tableRowKey;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy