Java Code Examples for org.apache.parquet.Preconditions#checkState()
The following examples show how to use
org.apache.parquet.Preconditions#checkState() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ColumnarBatchReader.java From iceberg with Apache License 2.0 | 6 votes |
@Override public final ColumnarBatch read(ColumnarBatch reuse, int numRowsToRead) { Preconditions.checkArgument(numRowsToRead > 0, "Invalid number of rows to read: %s", numRowsToRead); ColumnVector[] arrowColumnVectors = new ColumnVector[readers.length]; if (reuse == null) { closeVectors(); } for (int i = 0; i < readers.length; i += 1) { vectorHolders[i] = readers[i].read(vectorHolders[i], numRowsToRead); int numRowsInVector = vectorHolders[i].numValues(); Preconditions.checkState( numRowsInVector == numRowsToRead, "Number of rows in the vector %s didn't match expected %s ", numRowsInVector, numRowsToRead); arrowColumnVectors[i] = IcebergArrowColumnVector.forHolder(vectorHolders[i], numRowsInVector); } ColumnarBatch batch = new ColumnarBatch(arrowColumnVectors); batch.setNumRows(numRowsToRead); return batch; }
Example 2
Source File: Types.java From parquet-mr with Apache License 2.0 | 6 votes |
@Override protected Type build(String name) { Preconditions.checkState(logicalTypeAnnotation == null, "MAP is already a logical type and can't be changed."); if (keyType == null) { keyType = STRING_KEY; } GroupBuilder<GroupType> builder = buildGroup(repetition).as(OriginalType.MAP); if (id != null) { builder.id(id.intValue()); } if (valueType != null) { return builder .repeatedGroup().addFields(keyType, valueType).named("map") .named(name); } else { return builder .repeatedGroup().addFields(keyType).named("map") .named(name); } }
Example 3
Source File: Types.java From parquet-mr with Apache License 2.0 | 5 votes |
@Override protected Type build(String name) { Preconditions.checkState(logicalTypeAnnotation == null, "LIST is already the logical type and can't be changed"); Objects.requireNonNull(elementType, "List element type cannot be null"); GroupBuilder<GroupType> builder = buildGroup(repetition).as(OriginalType.LIST); if (id != null) { builder.id(id.intValue()); } return builder .repeatedGroup().addFields(elementType).named("list") .named(name); }
Example 4
Source File: DirectCodecFactory.java From parquet-mr with Apache License 2.0 | 5 votes |
/** * See docs on CodecFactory#createDirectCodecFactory which is how this class is * exposed publicly and is just a pass-through factory method for this constructor * to hide the rest of this class from public access. * * @throws NullPointerException if allocator is {@code null} */ DirectCodecFactory(Configuration config, ByteBufferAllocator allocator, int pageSize) { super(config, pageSize); this.allocator = Objects.requireNonNull(allocator, "allocator cannot be null"); Preconditions.checkState(allocator.isDirect(), "A %s requires a direct buffer allocator be provided.", getClass().getSimpleName()); }
Example 5
Source File: DynMethods.java From parquet-mr with Apache License 2.0 | 5 votes |
/** * Returns this method as a BoundMethod for the given receiver. * * @param receiver an Object to receive the method invocation * @return a {@link BoundMethod} for this method and the receiver * @throws IllegalStateException if the method is static * @throws IllegalArgumentException if the receiver's class is incompatible */ public BoundMethod bind(Object receiver) { Preconditions.checkState(!isStatic(), "Cannot bind static method " + method.toGenericString()); Preconditions.checkArgument( method.getDeclaringClass().isAssignableFrom(receiver.getClass()), "Cannot bind " + method.toGenericString() + " to instance of " + receiver.getClass()); return new BoundMethod(this, receiver); }
Example 6
Source File: ArrowVectorAccessors.java From iceberg with Apache License 2.0 | 4 votes |
@NotNull private static ArrowVectorAccessor getDictionaryVectorAccessor( Dictionary dictionary, ColumnDescriptor desc, FieldVector vector, PrimitiveType primitive) { Preconditions.checkState(vector instanceof IntVector, "Dictionary ids should be stored in IntVectors only"); if (primitive.getOriginalType() != null) { switch (desc.getPrimitiveType().getOriginalType()) { case ENUM: case JSON: case UTF8: case BSON: return new DictionaryStringAccessor((IntVector) vector, dictionary); case INT_64: case TIMESTAMP_MILLIS: case TIMESTAMP_MICROS: return new DictionaryLongAccessor((IntVector) vector, dictionary); case DECIMAL: switch (primitive.getPrimitiveTypeName()) { case BINARY: case FIXED_LEN_BYTE_ARRAY: return new DictionaryDecimalBinaryAccessor( (IntVector) vector, dictionary); case INT64: return new DictionaryDecimalLongAccessor( (IntVector) vector, dictionary); case INT32: return new DictionaryDecimalIntAccessor( (IntVector) vector, dictionary); default: throw new UnsupportedOperationException( "Unsupported base type for decimal: " + primitive.getPrimitiveTypeName()); } default: throw new UnsupportedOperationException( "Unsupported logical type: " + primitive.getOriginalType()); } } else { switch (primitive.getPrimitiveTypeName()) { case FIXED_LEN_BYTE_ARRAY: case BINARY: return new DictionaryBinaryAccessor((IntVector) vector, dictionary); case FLOAT: return new DictionaryFloatAccessor((IntVector) vector, dictionary); case INT64: return new DictionaryLongAccessor((IntVector) vector, dictionary); case DOUBLE: return new DictionaryDoubleAccessor((IntVector) vector, dictionary); default: throw new UnsupportedOperationException("Unsupported type: " + primitive); } } }
Example 7
Source File: FileSystemPlugin.java From dremio-oss with Apache License 2.0 | 4 votes |
@Override public CreateTableEntry createNewTable(SchemaConfig config, NamespaceKey key, IcebergTableProps icebergTableProps, WriterOptions writerOptions, Map<String, Object> storageOptions) { if(!getMutability().hasMutationCapability(MutationType.TABLE, config.isSystemUser())) { throw UserException.parseError() .message("Unable to create table. Schema [%s] is immutable for this user.", key.getParent()) .build(logger); } final String tableName = getTableName(key); final FormatPlugin formatPlugin; if (storageOptions == null || storageOptions.isEmpty() || !storageOptions.containsKey("type")) { final String storage = config.getOptions().getOption(ExecConstants.OUTPUT_FORMAT_VALIDATOR); formatPlugin = getFormatPlugin(storage); if (formatPlugin == null) { throw new UnsupportedOperationException(String.format("Unsupported format '%s' in '%s'", storage, key)); } } else { final FormatPluginConfig formatConfig = createConfigForTable(tableName, storageOptions); formatPlugin = getFormatPlugin(formatConfig); } final String userName = this.config.isImpersonationEnabled() ? config.getUserName() : SystemUser.SYSTEM_USERNAME; // check that there is no directory at the described path. Path path = resolveTablePathToValidPath(tableName); try { if (icebergTableProps == null || icebergTableProps.getIcebergOpType() == IcebergOperation.Type.CREATE) { if (systemUserFS.exists(path)) { throw UserException.validationError().message("Folder already exists at path: %s.", key).build(logger); } } else if (icebergTableProps.getIcebergOpType() == IcebergOperation.Type.INSERT) { if (!systemUserFS.exists(path)) { throw UserException.validationError().message("Table folder does not exists at path: %s.", key).build(logger); } } } catch (IOException e) { throw UserException.validationError(e).message("Failure to check if table already exists at path %s.", key).build(logger); } if (icebergTableProps != null) { icebergTableProps = new IcebergTableProps(icebergTableProps); icebergTableProps.setTableLocation(path.toString()); Preconditions.checkState(icebergTableProps.getUuid() != null && !icebergTableProps.getUuid().isEmpty(), "Unexpected state. UUID must be set"); path = path.resolve(icebergTableProps.getUuid()); } return new FileSystemCreateTableEntry( userName, this, formatPlugin, path.toString(), icebergTableProps, writerOptions); }
Example 8
Source File: Types.java From parquet-mr with Apache License 2.0 | 4 votes |
protected void setKeyType(Type keyType) { Preconditions.checkState(this.keyType == null, "Only one key type can be built with a MapBuilder"); this.keyType = keyType; }
Example 9
Source File: Types.java From parquet-mr with Apache License 2.0 | 4 votes |
protected void setValueType(Type valueType) { Preconditions.checkState(this.valueType == null, "Only one key type can be built with a ValueBuilder"); this.valueType = valueType; }
Example 10
Source File: Types.java From parquet-mr with Apache License 2.0 | 4 votes |
public THIS setElementType(Type elementType) { Preconditions.checkState(this.elementType == null, "Only one element can be built with a ListBuilder"); this.elementType = elementType; return self(); }
Example 11
Source File: ParquetFileWriter.java From parquet-mr with Apache License 2.0 | 4 votes |
public ParquetMetadata getFooter() { Preconditions.checkState(state == STATE.ENDED, "Cannot return unfinished footer."); return footer; }
Example 12
Source File: DynMethods.java From parquet-mr with Apache License 2.0 | 2 votes |
/** * Returns this method as a StaticMethod. * * @return a {@link StaticMethod} for this method * @throws IllegalStateException if the method is not static */ public StaticMethod asStatic() { Preconditions.checkState(isStatic(), "Method is not static"); return new StaticMethod(this); }