Search in sources :

Example 1 with IntRange

use of org.apache.commons.lang.math.IntRange in project pinot by linkedin.

the class GenerateDataCommand method buildCardinalityRangeMaps.

private void buildCardinalityRangeMaps(String file, HashMap<String, Integer> cardinality, HashMap<String, IntRange> range) throws JsonParseException, JsonMappingException, IOException {
    List<SchemaAnnotation> saList;
    if (file == null) {
        // Nothing to do here.
        return;
    }
    ObjectMapper objectMapper = new ObjectMapper();
    saList = objectMapper.readValue(new File(file), new TypeReference<List<SchemaAnnotation>>() {
    });
    for (SchemaAnnotation sa : saList) {
        String column = sa.getColumn();
        if (sa.isRange()) {
            range.put(column, new IntRange(sa.getRangeStart(), sa.getRangeEnd()));
        } else {
            cardinality.put(column, sa.getCardinality());
        }
    }
}
Also used : IntRange(org.apache.commons.lang.math.IntRange) TypeReference(org.codehaus.jackson.type.TypeReference) SchemaAnnotation(com.linkedin.pinot.tools.data.generator.SchemaAnnotation) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 2 with IntRange

use of org.apache.commons.lang.math.IntRange in project pinot by linkedin.

the class GenerateDataCommand method buildDataGeneratorSpec.

private DataGeneratorSpec buildDataGeneratorSpec(Schema schema, List<String> columns, HashMap<String, DataType> dataTypes, HashMap<String, FieldType> fieldTypes, HashMap<String, TimeUnit> timeUnits, HashMap<String, Integer> cardinality, HashMap<String, IntRange> range) {
    for (final FieldSpec fs : schema.getAllFieldSpecs()) {
        String col = fs.getName();
        columns.add(col);
        dataTypes.put(col, fs.getDataType());
        fieldTypes.put(col, fs.getFieldType());
        switch(fs.getFieldType()) {
            case DIMENSION:
                if (cardinality.get(col) == null) {
                    cardinality.put(col, 1000);
                }
                break;
            case METRIC:
                if (!range.containsKey(col)) {
                    range.put(col, new IntRange(1, 1000));
                }
                break;
            case TIME:
                if (!range.containsKey(col)) {
                    range.put(col, new IntRange(1, 1000));
                }
                TimeFieldSpec tfs = (TimeFieldSpec) fs;
                timeUnits.put(col, tfs.getIncomingGranularitySpec().getTimeType());
                break;
            default:
                throw new RuntimeException("Invalid field type.");
        }
    }
    return new DataGeneratorSpec(columns, cardinality, range, dataTypes, fieldTypes, timeUnits, FileFormat.AVRO, _outDir, _overwrite);
}
Also used : TimeFieldSpec(com.linkedin.pinot.common.data.TimeFieldSpec) IntRange(org.apache.commons.lang.math.IntRange) TimeFieldSpec(com.linkedin.pinot.common.data.TimeFieldSpec) FieldSpec(com.linkedin.pinot.common.data.FieldSpec) DataGeneratorSpec(com.linkedin.pinot.tools.data.generator.DataGeneratorSpec)

Example 3 with IntRange

use of org.apache.commons.lang.math.IntRange in project pinot by linkedin.

the class FileBasedSentineTest method setup.

@BeforeClass
public void setup() throws Exception {
    url = new URL("http://localhost:" + FileBasedServerBrokerStarters.BROKER_CLIENT_PORT + "/query");
    // lets generate data
    final String[] columns = { "dimention1", "dimention2", "dimention3", "dimention4", "metric1", "daysSinceEpoch" };
    final Map<String, DataType> dataTypes = new HashMap<String, FieldSpec.DataType>();
    final Map<String, FieldType> fieldTypes = new HashMap<String, FieldType>();
    final Map<String, TimeUnit> timeUnits = new HashMap<String, TimeUnit>();
    final Map<String, Integer> cardinality = new HashMap<String, Integer>();
    // Crate empty range map as the signature of DataGeneratorSpec has changed, and this test does not
    // use metric/time as fieldType.
    final Map<String, IntRange> range = new HashMap<String, IntRange>();
    for (final String col : columns) {
        if (col.equals("dimention1")) {
            dataTypes.put(col, DataType.STRING);
            cardinality.put(col, 1000);
        } else {
            dataTypes.put(col, DataType.INT);
            cardinality.put(col, 1000);
        }
        fieldTypes.put(col, FieldType.DIMENSION);
    }
    if (avroDataDir.exists()) {
        FileUtils.deleteDirectory(avroDataDir);
    }
    final DataGeneratorSpec spec = new DataGeneratorSpec(Arrays.asList(columns), cardinality, range, dataTypes, fieldTypes, timeUnits, FileFormat.AVRO, avroDataDir.getAbsolutePath(), true);
    generator = new DataGenerator();
    generator.init(spec);
    generator.generate(100000L, 2);
    // lets make segments now
    final File bootstrapDir = new File(FileBasedServerBrokerStarters.SERVER_BOOTSTRAP_DIR);
    if (bootstrapDir.exists()) {
        FileUtils.deleteDirectory(bootstrapDir);
    }
    bootstrapDir.mkdir();
    int counter = 0;
    for (final File avro : avroDataDir.listFiles()) {
        for (final String table : FileBasedServerBrokerStarters.TABLE_NAMES) {
            final SegmentGeneratorConfig genConfig = SegmentTestUtils.getSegmentGenSpecWithSchemAndProjectedColumns(avro, new File(bootstrapDir, "segment-" + counter), "daysSinceEpoch", TimeUnit.DAYS, table);
            final SegmentIndexCreationDriver driver = SegmentCreationDriverFactory.get(null);
            driver.init(genConfig);
            driver.build();
            counter++;
        }
    }
    // lets start the server and the broker now
    starter = new FileBasedServerBrokerStarters();
    starter.startAll();
    // pick some values from here if you need to use it for running filter queries
    final JSONObject selectionRequestResponse = postQuery("select * from 'table1' limit 100", "http://localhost:" + FileBasedServerBrokerStarters.BROKER_CLIENT_PORT);
//    System.out.println(selectionRequestResponse.toString(1));
}
Also used : SegmentIndexCreationDriver(com.linkedin.pinot.core.segment.creator.SegmentIndexCreationDriver) HashMap(java.util.HashMap) IntRange(org.apache.commons.lang.math.IntRange) URL(java.net.URL) FieldSpec(com.linkedin.pinot.common.data.FieldSpec) FieldType(com.linkedin.pinot.common.data.FieldSpec.FieldType) JSONObject(org.json.JSONObject) DataGenerator(com.linkedin.pinot.tools.data.generator.DataGenerator) SegmentGeneratorConfig(com.linkedin.pinot.core.indexsegment.generator.SegmentGeneratorConfig) DataType(com.linkedin.pinot.common.data.FieldSpec.DataType) TimeUnit(java.util.concurrent.TimeUnit) File(java.io.File) DataGeneratorSpec(com.linkedin.pinot.tools.data.generator.DataGeneratorSpec) BeforeClass(org.testng.annotations.BeforeClass)

Example 4 with IntRange

use of org.apache.commons.lang.math.IntRange in project intellij-elixir by KronicDeth.

the class ArityInterval method arityInterval.

/*
     * Static Methods
     */
static ArityInterval arityInterval(@NotNull Pair<String, IntRange> nameArityRange, @NotNull ResolveState resolveState) {
    @Nullable String modularCanonicalName = resolveState.get(MODULAR_CANONICAL_NAME);
    IntRange arityRange = nameArityRange.second;
    int arityRangeMinimum = arityRange.getMinimumInteger();
    int arityRangeMaximum = arityRange.getMaximumInteger();
    ArityInterval arityInterval = null;
    if (modularCanonicalName != null && modularCanonicalName.equals(KERNEL_SPECIAL_FORMS)) {
        String name = nameArityRange.first;
        arityInterval = KERNEL_SPECIAL_FORM_ARITY_INTERVAL_BY_NAME.get(name);
    }
    if (arityInterval == null) {
        arityInterval = new ArityInterval(arityRangeMinimum, arityRangeMaximum);
    }
    return arityInterval;
}
Also used : IntRange(org.apache.commons.lang.math.IntRange) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with IntRange

use of org.apache.commons.lang.math.IntRange in project intellij-elixir by KronicDeth.

the class ElixirPsiImplUtil method resolvedFinalArityRange.

@Contract(pure = true)
@NotNull
public static IntRange resolvedFinalArityRange(@NotNull final Call call) {
    IntRange arityRange;
    PsiElement[] finalArguments = ElixirPsiImplUtil.finalArguments(call);
    if (finalArguments != null) {
        int defaultCount = defaultArgumentCount(finalArguments);
        int maximum = finalArguments.length;
        int minimum = maximum - defaultCount;
        arityRange = new IntRange(minimum, maximum);
    } else {
        arityRange = new IntRange(0);
    }
    return arityRange;
}
Also used : IntRange(org.apache.commons.lang.math.IntRange) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

IntRange (org.apache.commons.lang.math.IntRange)31 Call (org.elixir_lang.psi.call.Call)10 PsiElement (com.intellij.psi.PsiElement)6 File (java.io.File)6 Nullable (org.jetbrains.annotations.Nullable)6 ArrayList (java.util.ArrayList)5 NotNull (org.jetbrains.annotations.NotNull)4 Test (org.testng.annotations.Test)4 Pair (com.intellij.openapi.util.Pair)3 DataType (com.linkedin.pinot.common.data.FieldSpec.DataType)3 DataGeneratorSpec (com.linkedin.pinot.tools.data.generator.DataGeneratorSpec)3 List (java.util.List)3 AtUnqualifiedNoParenthesesCall (org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall)3 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)2 PsiReference (com.intellij.psi.PsiReference)2 FieldSpec (com.linkedin.pinot.common.data.FieldSpec)2 FieldType (com.linkedin.pinot.common.data.FieldSpec.FieldType)2 DataGenerator (com.linkedin.pinot.tools.data.generator.DataGenerator)2 HashMap (java.util.HashMap)2 TimeUnit (java.util.concurrent.TimeUnit)2