carbondata-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ravipesala <...@git.apache.org>
Subject [GitHub] carbondata pull request #987: [CARBONDATA-1017] Add EncodingStrategy and use...
Date Tue, 13 Jun 2017 04:35:14 GMT
Github user ravipesala commented on a diff in the pull request:

    https://github.com/apache/carbondata/pull/987#discussion_r121580534
  
    --- Diff: core/src/main/java/org/apache/carbondata/core/datastore/page/encoding/AdaptiveIntegerCodec.java
---
    @@ -0,0 +1,213 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You 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 org.apache.carbondata.core.datastore.page.encoding;
    +
    +import org.apache.carbondata.core.datastore.compression.Compressor;
    +import org.apache.carbondata.core.datastore.page.ColumnPage;
    +import org.apache.carbondata.core.datastore.page.LazyColumnPage;
    +import org.apache.carbondata.core.datastore.page.PrimitiveCodec;
    +import org.apache.carbondata.core.datastore.page.statistics.ColumnPageStatsVO;
    +import org.apache.carbondata.core.metadata.datatype.DataType;
    +
    +/**
    + * Codec for integer (byte, short, int, long) data type page.
    + * This codec will do type casting on page data to make storage minimum.
    + */
    +class AdaptiveIntegerCodec extends AdaptiveCompressionCodec {
    +
    +  private ColumnPage encodedPage;
    +
    +  public static ColumnPageCodec newInstance(DataType srcDataType, DataType targetDataType,
    +      ColumnPageStatsVO stats, Compressor compressor) {
    +    return new AdaptiveIntegerCodec(srcDataType, targetDataType, stats, compressor);
    +  }
    +
    +  private AdaptiveIntegerCodec(DataType srcDataType, DataType targetDataType,
    +      ColumnPageStatsVO stats, Compressor compressor) {
    +    super(srcDataType, targetDataType, stats, compressor);
    +  }
    +
    +  @Override
    +  public String getName() {
    +    return "AdaptiveIntegerCodec";
    +  }
    +
    +  @Override
    +  public byte[] encode(ColumnPage input) {
    +    if (srcDataType.equals(targetDataType)) {
    +      return input.compress(compressor);
    +    } else {
    +      encodedPage = ColumnPage.newPage(targetDataType, input.getPageSize());
    +      input.encode(codec);
    +      return encodedPage.compress(compressor);
    +    }
    +  }
    +
    +  @Override
    +  public ColumnPage decode(byte[] input, int offset, int length) {
    +    if (srcDataType.equals(targetDataType)) {
    +      return ColumnPage.decompress(compressor, targetDataType, input, offset, length);
    +    } else {
    +      ColumnPage page = ColumnPage.decompress(compressor, targetDataType, input, offset,
length);
    +      return LazyColumnPage.newPage(page, codec);
    +    }
    +  }
    +
    +  private PrimitiveCodec codec = new PrimitiveCodec() {
    +    @Override
    +    public void encode(int rowId, byte value) {
    +      switch (targetDataType) {
    +        default:
    +          assert (false);
    +          throw new RuntimeException("internal error: " + debugInfo());
    +      }
    +    }
    +
    +    @Override
    +    public void encode(int rowId, short value) {
    +      switch (targetDataType) {
    +        case BYTE:
    +          encodedPage.putByte(rowId, (byte) value);
    +          break;
    +        default:
    +          assert (false);
    --- End diff --
    
    This assertion is not required as we are already throwing exception


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message