/** * <p> * The type of the target field, which is the type of the return value of the * partition function. * </p> * @since 0.8.0 */ public Class<? extends T> getType(Class<? extends S> sourceType) { return getType(); }
@SuppressWarnings("unchecked") public static <S, T> Class<? extends T> getPartitionType(FieldPartitioner<S, T> fp, Schema schema) { if (fp instanceof ProvidedFieldPartitioner) { // provided partitioners have no source field schema return fp.getType(); } Class<? extends S> inputType = (Class<S>) getClassForType( fieldSchema(schema, fp.getSourceName()).getType()); return fp.getType(inputType); }
private <S, T> T valueFor(FieldPartitioner<S, T> fp) { if (values.containsKey(fp.getName())) { return Conversions.convert(values.get(fp.getName()), fp.getType()); } else if (values.containsKey(fp.getSourceName())) { return fp.apply(Conversions.convert( values.get(fp.getSourceName()), fp.getSourceType())); } else { throw new IllegalStateException( "Cannot create StorageKey, missing data for field:" + fp.getName()); } } }
public static void checkStrategyUpdate(PartitionStrategy existing, PartitionStrategy other, Schema schema) { List<FieldPartitioner> existingFields = Accessor.getDefault() .getFieldPartitioners(existing); List<FieldPartitioner> otherFields = Accessor.getDefault() .getFieldPartitioners(other); ValidationException.check(existingFields.size() == otherFields.size(), "Not compatible: cannot replace %s partitioners with %s partitioners", existingFields.size(), otherFields.size()); for (int i = 0; i < existingFields.size(); i += 1) { FieldPartitioner fp = existingFields.get(i); FieldPartitioner replacement = otherFields.get(i); if (fp.equals(replacement)) { continue; } ValidationException.check(fp instanceof ProvidedFieldPartitioner, "Cannot replace partition %s: not a provided partitioner", fp.getName()); ValidationException.check(fp.getName().equals(replacement.getName()), "Cannot change the name of partition %s (to %s)", fp.getName(), replacement.getName()); Class<?> outputType = SchemaUtil.getPartitionType(replacement, schema); ValidationException.check( isCompatibleWithProvidedType(fp.getType(), outputType), "Cannot change the data type of partition %s", fp.getName()); } }
return String.format("identity(\"%s\", \"%s\", \"%s\", %s)", fieldPartitioner.getSourceName(), fieldPartitioner.getName(), fieldPartitioner.getType().getName(), fieldPartitioner.getCardinality()); } else if (fieldPartitioner instanceof RangeFieldPartitioner) {
/** * Return the value of a {@code FieldPartitioner} field for this {@link Marker}. * * If the {@code Marker} has a value for the field's name, that value is * returned using {@link Marker#getAs(java.lang.String, java.lang.Class)}. If * the {@code Marker} only has a value for the the source field name, then * that value is retrieved using * {@link org.kitesdk.data.spi.Marker#getAs(java.lang.String, * java.lang.Class)} and the field's transformation is applied to it as the source value. * * @param fp a {@code FieldPartitioner} * @return the value of the field for this {@code marker}, or null * @since 0.9.0 */ @Nullable public <S, T> T valueFor(FieldPartitioner<S, T> fp) { if (has(fp.getName())) { return getAs(fp.getName(), fp.getType()); } else if (has(fp.getSourceName())) { return fp.apply(getAs(fp.getSourceName(), fp.getSourceType())); } else { return null; } }