com.linkedin.pinot.segments.v1.creator.BlocksTest.java Source code

Java tutorial

Introduction

Here is the source code for com.linkedin.pinot.segments.v1.creator.BlocksTest.java

Source

/**
 * Copyright (C) 2014-2016 LinkedIn Corp. (pinot-core@linkedin.com)
 *
 * 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 com.linkedin.pinot.segments.v1.creator;

import java.io.File;
import java.util.concurrent.TimeUnit;

import org.apache.avro.Schema.Field;
import org.apache.avro.file.DataFileStream;
import org.apache.avro.generic.GenericRecord;
import org.apache.commons.io.FileUtils;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

import com.linkedin.pinot.core.indexsegment.generator.SegmentGeneratorConfig;
import com.linkedin.pinot.core.indexsegment.utils.AvroUtils;
import com.linkedin.pinot.core.segment.creator.SegmentIndexCreationDriver;
import com.linkedin.pinot.core.segment.creator.impl.SegmentCreationDriverFactory;
import com.linkedin.pinot.util.TestUtils;

public class BlocksTest {

    private static final String AVRO_DATA = "data/test_data-mv.avro";
    private static File INDEX_DIR = new File(
            FileUtils.getTempDirectory() + File.separator + IntArraysTest.class.getName());

    @AfterClass
    public static void cleanup() {
        FileUtils.deleteQuietly(INDEX_DIR);
    }

    @BeforeClass
    public static void before() throws Exception {
        final String filePath = TestUtils
                .getFileFromResourceUrl(BlocksTest.class.getClassLoader().getResource(AVRO_DATA));
        if (INDEX_DIR.exists()) {
            FileUtils.deleteQuietly(INDEX_DIR);
        }

        System.out.println(INDEX_DIR.getAbsolutePath());
        final SegmentIndexCreationDriver driver = SegmentCreationDriverFactory.get(null);

        final SegmentGeneratorConfig config = SegmentTestUtils.getSegmentGenSpecWithSchemAndProjectedColumns(
                new File(filePath), INDEX_DIR, "daysSinceEpoch", TimeUnit.DAYS, "test");
        config.setTimeColumnName("daysSinceEpoch");
        driver.init(config);
        driver.build();

        final DataFileStream<GenericRecord> avroReader = AvroUtils.getAvroReader(new File(filePath));
        final org.apache.avro.Schema avroSchema = avroReader.getSchema();
        final String[] columns = new String[avroSchema.getFields().size()];
        int i = 0;
        for (final Field f : avroSchema.getFields()) {
            columns[i] = f.name();
            i++;
        }
    }
}