Search in sources :

Example 1 with IBinaryComparatorFactory

use of org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory in project asterixdb by apache.

the class RangeMapBuilder method verifyRangeOrder.

public static void verifyRangeOrder(IRangeMap rangeMap, boolean ascending) throws CompilationException {
    // TODO Add support for composite fields.
    int fieldIndex = 0;
    int fieldType = rangeMap.getTag(0, 0);
    BinaryComparatorFactoryProvider comparatorFactory = BinaryComparatorFactoryProvider.INSTANCE;
    IBinaryComparatorFactory bcf = comparatorFactory.getBinaryComparatorFactory(ATypeTag.VALUE_TYPE_MAPPING[fieldType], ascending);
    IBinaryComparator comparator = bcf.createBinaryComparator();
    int c = 0;
    for (int split = 1; split < rangeMap.getSplitCount(); ++split) {
        if (fieldType != rangeMap.getTag(fieldIndex, split)) {
            throw new CompilationException("Range field contains more than a single type of items (" + fieldType + " and " + rangeMap.getTag(fieldIndex, split) + ").");
        }
        int previousSplit = split - 1;
        try {
            c = comparator.compare(rangeMap.getByteArray(fieldIndex, previousSplit), rangeMap.getStartOffset(fieldIndex, previousSplit), rangeMap.getLength(fieldIndex, previousSplit), rangeMap.getByteArray(fieldIndex, split), rangeMap.getStartOffset(fieldIndex, split), rangeMap.getLength(fieldIndex, split));
        } catch (HyracksDataException e) {
            throw new CompilationException(e);
        }
        if (c >= 0) {
            throw new CompilationException("Range fields are not in sorted order.");
        }
    }
}
Also used : BinaryComparatorFactoryProvider(org.apache.asterix.formats.nontagged.BinaryComparatorFactoryProvider) CompilationException(org.apache.asterix.common.exceptions.CompilationException) IBinaryComparatorFactory(org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory) IBinaryComparator(org.apache.hyracks.api.dataflow.value.IBinaryComparator) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 2 with IBinaryComparatorFactory

use of org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory in project asterixdb by apache.

the class MetadataProvider method getComparatorFactoriesAndTypeTraitsOfSecondaryBTreeIndex.

private Pair<IBinaryComparatorFactory[], ITypeTraits[]> getComparatorFactoriesAndTypeTraitsOfSecondaryBTreeIndex(List<List<String>> sidxKeyFieldNames, List<IAType> sidxKeyFieldTypes, List<List<String>> pidxKeyFieldNames, ARecordType recType, DatasetType dsType, boolean hasMeta, List<Integer> primaryIndexKeyIndicators, List<Integer> secondaryIndexIndicators, ARecordType metaType) throws AlgebricksException {
    IBinaryComparatorFactory[] comparatorFactories;
    ITypeTraits[] typeTraits;
    int sidxKeyFieldCount = sidxKeyFieldNames.size();
    int pidxKeyFieldCount = pidxKeyFieldNames.size();
    typeTraits = new ITypeTraits[sidxKeyFieldCount + pidxKeyFieldCount];
    comparatorFactories = new IBinaryComparatorFactory[sidxKeyFieldCount + pidxKeyFieldCount];
    int i = 0;
    for (; i < sidxKeyFieldCount; ++i) {
        Pair<IAType, Boolean> keyPairType = Index.getNonNullableOpenFieldType(sidxKeyFieldTypes.get(i), sidxKeyFieldNames.get(i), (hasMeta && secondaryIndexIndicators.get(i).intValue() == 1) ? metaType : recType);
        IAType keyType = keyPairType.first;
        comparatorFactories[i] = BinaryComparatorFactoryProvider.INSTANCE.getBinaryComparatorFactory(keyType, true);
        typeTraits[i] = TypeTraitProvider.INSTANCE.getTypeTrait(keyType);
    }
    for (int j = 0; j < pidxKeyFieldCount; ++j, ++i) {
        IAType keyType = null;
        try {
            switch(dsType) {
                case INTERNAL:
                    keyType = (hasMeta && primaryIndexKeyIndicators.get(j).intValue() == 1) ? metaType.getSubFieldType(pidxKeyFieldNames.get(j)) : recType.getSubFieldType(pidxKeyFieldNames.get(j));
                    break;
                case EXTERNAL:
                    keyType = IndexingConstants.getFieldType(j);
                    break;
                default:
                    throw new AlgebricksException("Unknown Dataset Type");
            }
        } catch (AsterixException e) {
            throw new AlgebricksException(e);
        }
        comparatorFactories[i] = BinaryComparatorFactoryProvider.INSTANCE.getBinaryComparatorFactory(keyType, true);
        typeTraits[i] = TypeTraitProvider.INSTANCE.getTypeTrait(keyType);
    }
    return new Pair<>(comparatorFactories, typeTraits);
}
Also used : AsterixException(org.apache.asterix.common.exceptions.AsterixException) ITypeTraits(org.apache.hyracks.api.dataflow.value.ITypeTraits) IBinaryComparatorFactory(org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) AlgebricksPartitionConstraint(org.apache.hyracks.algebricks.common.constraints.AlgebricksPartitionConstraint) DatasetCardinalityHint(org.apache.asterix.metadata.dataset.hints.DatasetHints.DatasetCardinalityHint) AlgebricksAbsolutePartitionConstraint(org.apache.hyracks.algebricks.common.constraints.AlgebricksAbsolutePartitionConstraint) IAType(org.apache.asterix.om.types.IAType) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 3 with IBinaryComparatorFactory

use of org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory in project asterixdb by apache.

the class BTreeResourceFactoryProvider method getResourceFactory.

@Override
public IResourceFactory getResourceFactory(MetadataProvider mdProvider, Dataset dataset, Index index, ARecordType recordType, ARecordType metaType, ILSMMergePolicyFactory mergePolicyFactory, Map<String, String> mergePolicyProperties, ITypeTraits[] filterTypeTraits, IBinaryComparatorFactory[] filterCmpFactories) throws AlgebricksException {
    int[] filterFields = IndexUtil.getFilterFields(dataset, index, filterTypeTraits);
    int[] btreeFields = IndexUtil.getBtreeFieldsIfFiltered(dataset, index);
    IStorageComponentProvider storageComponentProvider = mdProvider.getStorageComponentProvider();
    ITypeTraits[] typeTraits = getTypeTraits(mdProvider, dataset, index, recordType, metaType);
    IBinaryComparatorFactory[] cmpFactories = getCmpFactories(mdProvider, dataset, index, recordType, metaType);
    int[] bloomFilterFields = getBloomFilterFields(dataset, index);
    boolean durable = !dataset.isTemp();
    double bloomFilterFalsePositiveRate = mdProvider.getStorageProperties().getBloomFilterFalsePositiveRate();
    ILSMOperationTrackerFactory opTrackerFactory = dataset.getIndexOperationTrackerFactory(index);
    ILSMIOOperationCallbackFactory ioOpCallbackFactory = dataset.getIoOperationCallbackFactory(index);
    IStorageManager storageManager = storageComponentProvider.getStorageManager();
    IMetadataPageManagerFactory metadataPageManagerFactory = storageComponentProvider.getMetadataPageManagerFactory();
    ILSMIOOperationSchedulerProvider ioSchedulerProvider = storageComponentProvider.getIoOperationSchedulerProvider();
    switch(dataset.getDatasetType()) {
        case EXTERNAL:
            return index.getIndexName().equals(IndexingConstants.getFilesIndexName(dataset.getDatasetName())) ? new ExternalBTreeLocalResourceFactory(storageManager, typeTraits, cmpFactories, filterTypeTraits, filterCmpFactories, filterFields, opTrackerFactory, ioOpCallbackFactory, metadataPageManagerFactory, ioSchedulerProvider, mergePolicyFactory, mergePolicyProperties, durable, bloomFilterFields, bloomFilterFalsePositiveRate, false, btreeFields) : new ExternalBTreeWithBuddyLocalResourceFactory(storageManager, typeTraits, cmpFactories, filterTypeTraits, filterCmpFactories, filterFields, opTrackerFactory, ioOpCallbackFactory, metadataPageManagerFactory, ioSchedulerProvider, mergePolicyFactory, mergePolicyProperties, durable, bloomFilterFields, bloomFilterFalsePositiveRate, false, btreeFields);
        case INTERNAL:
            AsterixVirtualBufferCacheProvider vbcProvider = new AsterixVirtualBufferCacheProvider(dataset.getDatasetId());
            return new LSMBTreeLocalResourceFactory(storageManager, typeTraits, cmpFactories, filterTypeTraits, filterCmpFactories, filterFields, opTrackerFactory, ioOpCallbackFactory, metadataPageManagerFactory, vbcProvider, ioSchedulerProvider, mergePolicyFactory, mergePolicyProperties, durable, bloomFilterFields, bloomFilterFalsePositiveRate, index.isPrimaryIndex(), btreeFields);
        default:
            throw new CompilationException(ErrorCode.COMPILATION_UNKNOWN_DATASET_TYPE, dataset.getDatasetType().toString());
    }
}
Also used : CompilationException(org.apache.asterix.common.exceptions.CompilationException) ILSMIOOperationCallbackFactory(org.apache.hyracks.storage.am.lsm.common.api.ILSMIOOperationCallbackFactory) IStorageComponentProvider(org.apache.asterix.common.context.IStorageComponentProvider) ExternalBTreeLocalResourceFactory(org.apache.hyracks.storage.am.lsm.btree.dataflow.ExternalBTreeLocalResourceFactory) ITypeTraits(org.apache.hyracks.api.dataflow.value.ITypeTraits) IMetadataPageManagerFactory(org.apache.hyracks.storage.am.common.api.IMetadataPageManagerFactory) IBinaryComparatorFactory(org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory) AsterixVirtualBufferCacheProvider(org.apache.asterix.common.context.AsterixVirtualBufferCacheProvider) ILSMOperationTrackerFactory(org.apache.hyracks.storage.am.lsm.common.api.ILSMOperationTrackerFactory) ExternalBTreeWithBuddyLocalResourceFactory(org.apache.hyracks.storage.am.lsm.btree.dataflow.ExternalBTreeWithBuddyLocalResourceFactory) IStorageManager(org.apache.hyracks.storage.common.IStorageManager) ILSMIOOperationSchedulerProvider(org.apache.hyracks.storage.am.lsm.common.api.ILSMIOOperationSchedulerProvider) LSMBTreeLocalResourceFactory(org.apache.hyracks.storage.am.lsm.btree.dataflow.LSMBTreeLocalResourceFactory)

Example 4 with IBinaryComparatorFactory

use of org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory in project asterixdb by apache.

the class BTreeResourceFactoryProvider method getCmpFactories.

private static IBinaryComparatorFactory[] getCmpFactories(MetadataProvider metadataProvider, Dataset dataset, Index index, ARecordType recordType, ARecordType metaType) throws AlgebricksException {
    IBinaryComparatorFactory[] primaryCmpFactories = dataset.getPrimaryComparatorFactories(metadataProvider, recordType, metaType);
    if (index.isPrimaryIndex()) {
        return dataset.getPrimaryComparatorFactories(metadataProvider, recordType, metaType);
    } else if (dataset.getDatasetType() == DatasetType.EXTERNAL && index.getIndexName().equals(IndexingConstants.getFilesIndexName(dataset.getDatasetName()))) {
        return FilesIndexDescription.FILES_INDEX_COMP_FACTORIES;
    }
    int numPrimaryKeys = dataset.getPrimaryKeys().size();
    int numSecondaryKeys = index.getKeyFieldNames().size();
    IBinaryComparatorFactoryProvider cmpFactoryProvider = metadataProvider.getStorageComponentProvider().getComparatorFactoryProvider();
    IBinaryComparatorFactory[] secondaryCmpFactories = new IBinaryComparatorFactory[numSecondaryKeys + numPrimaryKeys];
    for (int i = 0; i < numSecondaryKeys; i++) {
        ARecordType sourceType;
        List<Integer> keySourceIndicators = index.getKeyFieldSourceIndicators();
        if (keySourceIndicators == null || keySourceIndicators.get(i) == 0) {
            sourceType = recordType;
        } else {
            sourceType = metaType;
        }
        Pair<IAType, Boolean> keyTypePair = Index.getNonNullableOpenFieldType(index.getKeyFieldTypes().get(i), index.getKeyFieldNames().get(i), sourceType);
        IAType keyType = keyTypePair.first;
        secondaryCmpFactories[i] = cmpFactoryProvider.getBinaryComparatorFactory(keyType, true);
    }
    // Add serializers and comparators for primary index fields.
    for (int i = 0; i < numPrimaryKeys; i++) {
        secondaryCmpFactories[numSecondaryKeys + i] = primaryCmpFactories[i];
    }
    return secondaryCmpFactories;
}
Also used : IBinaryComparatorFactory(org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory) IBinaryComparatorFactoryProvider(org.apache.hyracks.algebricks.data.IBinaryComparatorFactoryProvider) ARecordType(org.apache.asterix.om.types.ARecordType) IAType(org.apache.asterix.om.types.IAType)

Example 5 with IBinaryComparatorFactory

use of org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory in project asterixdb by apache.

the class MetadataBootstrap method enlistMetadataDataset.

/**
     * Enlist a metadata index so it is available for metadata operations
     * should be performed upon bootstrapping
     *
     * @param index
     * @throws HyracksDataException
     */
public static void enlistMetadataDataset(INCServiceContext ncServiceCtx, IMetadataIndex index) throws HyracksDataException {
    ClusterPartition metadataPartition = appContext.getMetadataProperties().getMetadataPartition();
    int metadataDeviceId = metadataPartition.getIODeviceNum();
    String metadataPartitionPath = StoragePathUtil.prepareStoragePartitionPath(ClusterProperties.INSTANCE.getStorageDirectoryName(), metadataPartition.getPartitionId());
    String resourceName = metadataPartitionPath + File.separator + index.getFileNameRelativePath();
    FileReference file = ioManager.getFileReference(metadataDeviceId, resourceName);
    index.setFile(file);
    ITypeTraits[] typeTraits = index.getTypeTraits();
    IBinaryComparatorFactory[] cmpFactories = index.getKeyBinaryComparatorFactory();
    int[] bloomFilterKeyFields = index.getBloomFilterKeyFields();
    // opTrackerProvider and ioOpCallbackFactory should both be acquired through IStorageManager
    // We are unable to do this since IStorageManager needs a dataset to determine the appropriate
    // objects
    ILSMOperationTrackerFactory opTrackerFactory = index.isPrimaryIndex() ? new PrimaryIndexOperationTrackerFactory(index.getDatasetId().getId()) : new SecondaryIndexOperationTrackerFactory(index.getDatasetId().getId());
    ILSMIOOperationCallbackFactory ioOpCallbackFactory = LSMBTreeIOOperationCallbackFactory.INSTANCE;
    IStorageComponentProvider storageComponentProvider = appContext.getStorageComponentProvider();
    if (isNewUniverse()) {
        LSMBTreeLocalResourceFactory lsmBtreeFactory = new LSMBTreeLocalResourceFactory(storageComponentProvider.getStorageManager(), typeTraits, cmpFactories, null, null, null, opTrackerFactory, ioOpCallbackFactory, storageComponentProvider.getMetadataPageManagerFactory(), new AsterixVirtualBufferCacheProvider(index.getDatasetId().getId()), storageComponentProvider.getIoOperationSchedulerProvider(), appContext.getMetadataMergePolicyFactory(), GlobalConfig.DEFAULT_COMPACTION_POLICY_PROPERTIES, true, bloomFilterKeyFields, appContext.getBloomFilterFalsePositiveRate(), true, null);
        DatasetLocalResourceFactory dsLocalResourceFactory = new DatasetLocalResourceFactory(index.getDatasetId().getId(), lsmBtreeFactory);
        // TODO(amoudi) Creating the index should be done through the same code path as other indexes
        // This is to be done by having a metadata dataset associated with each index
        IIndexBuilder indexBuilder = new IndexBuilder(ncServiceCtx, storageComponentProvider.getStorageManager(), index::getResourceId, file, dsLocalResourceFactory, true);
        indexBuilder.build();
    } else {
        final LocalResource resource = localResourceRepository.get(file.getRelativePath());
        if (resource == null) {
            throw new HyracksDataException("Could not find required metadata indexes. Please delete " + appContext.getMetadataProperties().getTransactionLogDirs().get(appContext.getTransactionSubsystem().getId()) + " to intialize as a new instance. (WARNING: all data will be lost.)");
        }
        // Why do we care about metadata dataset's resource ids? why not assign them ids similar to other resources?
        if (index.getResourceId() != resource.getId()) {
            throw new HyracksDataException("Resource Id doesn't match expected metadata index resource id");
        }
        IndexDataflowHelper indexHelper = new IndexDataflowHelper(ncServiceCtx, storageComponentProvider.getStorageManager(), file);
        // Opening the index through the helper will ensure it gets instantiated
        indexHelper.open();
        indexHelper.close();
    }
}
Also used : DatasetLocalResourceFactory(org.apache.asterix.transaction.management.resource.DatasetLocalResourceFactory) ILSMIOOperationCallbackFactory(org.apache.hyracks.storage.am.lsm.common.api.ILSMIOOperationCallbackFactory) IStorageComponentProvider(org.apache.asterix.common.context.IStorageComponentProvider) ITypeTraits(org.apache.hyracks.api.dataflow.value.ITypeTraits) IBinaryComparatorFactory(org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory) AsterixVirtualBufferCacheProvider(org.apache.asterix.common.context.AsterixVirtualBufferCacheProvider) ILSMOperationTrackerFactory(org.apache.hyracks.storage.am.lsm.common.api.ILSMOperationTrackerFactory) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IIndexBuilder(org.apache.hyracks.storage.am.common.api.IIndexBuilder) IndexBuilder(org.apache.hyracks.storage.am.common.build.IndexBuilder) LocalResource(org.apache.hyracks.storage.common.LocalResource) SecondaryIndexOperationTrackerFactory(org.apache.asterix.transaction.management.opcallbacks.SecondaryIndexOperationTrackerFactory) IIndexBuilder(org.apache.hyracks.storage.am.common.api.IIndexBuilder) LSMBTreeLocalResourceFactory(org.apache.hyracks.storage.am.lsm.btree.dataflow.LSMBTreeLocalResourceFactory) FileReference(org.apache.hyracks.api.io.FileReference) IndexDataflowHelper(org.apache.hyracks.storage.am.common.dataflow.IndexDataflowHelper) PrimaryIndexOperationTrackerFactory(org.apache.asterix.transaction.management.opcallbacks.PrimaryIndexOperationTrackerFactory) ClusterPartition(org.apache.asterix.common.cluster.ClusterPartition)

Aggregations

IBinaryComparatorFactory (org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory)86 ITypeTraits (org.apache.hyracks.api.dataflow.value.ITypeTraits)45 RecordDescriptor (org.apache.hyracks.api.dataflow.value.RecordDescriptor)25 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)25 Test (org.junit.Test)25 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)24 ArrayTupleReference (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleReference)22 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)19 UTF8StringSerializerDeserializer (org.apache.hyracks.dataflow.common.data.marshalling.UTF8StringSerializerDeserializer)19 ITreeIndex (org.apache.hyracks.storage.am.common.api.ITreeIndex)17 IIndexAccessor (org.apache.hyracks.storage.common.IIndexAccessor)16 JobSpecification (org.apache.hyracks.api.job.JobSpecification)15 OneToOneConnectorDescriptor (org.apache.hyracks.dataflow.std.connectors.OneToOneConnectorDescriptor)15 IBinaryComparatorFactoryProvider (org.apache.hyracks.algebricks.data.IBinaryComparatorFactoryProvider)14 FieldHashPartitionComputerFactory (org.apache.hyracks.dataflow.common.data.partition.FieldHashPartitionComputerFactory)14 IFileSplitProvider (org.apache.hyracks.dataflow.std.file.IFileSplitProvider)13 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)11 IVariableTypeEnvironment (org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment)11 MToNPartitioningMergingConnectorDescriptor (org.apache.hyracks.dataflow.std.connectors.MToNPartitioningMergingConnectorDescriptor)10 IPrimitiveValueProviderFactory (org.apache.hyracks.storage.am.common.api.IPrimitiveValueProviderFactory)10