/** * Initialize the format with the given desired schema and properties. * Guaranteed to be called once before any other method is called. * * @param formatSpecification the specification for the format, containing the desired schema and settings * @throws UnsupportedTypeException if the desired schema and properties are not supported */ public void initialize(@Nullable FormatSpecification formatSpecification) throws UnsupportedTypeException { Schema desiredSchema = null; Map<String, String> settings = Collections.emptyMap(); if (formatSpecification != null) { desiredSchema = formatSpecification.getSchema(); settings = formatSpecification.getSettings(); } desiredSchema = desiredSchema == null ? getDefaultSchema() : desiredSchema; if (desiredSchema == null) { String msg = "A schema must be provided to the format: "; if (formatSpecification != null) { msg += formatSpecification.getName(); } throw new UnsupportedTypeException(msg); } validateIsRecord(desiredSchema); validateSchema(desiredSchema); this.schema = desiredSchema; configure(settings); }
@Nullable @Override public String getSchemaToAdd() { Schema schema = viewSpec.getFormat().getSchema(); if (schema == null) { FormatSpecification format = viewSpec.getFormat(); RecordFormat<Object, Object> initializedFormat; try { initializedFormat = RecordFormats.createInitializedFormat(format); schema = initializedFormat.getSchema(); } catch (IllegalAccessException | InstantiationException | UnsupportedTypeException | ClassNotFoundException e) { LOG.debug("Exception: ", e); LOG.warn("Exception while determining schema for view {}. View {} will not contain schema as metadata.", viewId, viewId); } } return schema == null ? null : schema.toString(); } }
format.initialize(actualSpec); return format;
@Override public DecodeResult<LongWritable, GenericStreamEventData<T>> decode( StreamEvent event, DecodeResult<LongWritable, GenericStreamEventData<T>> result) { key.set(event.getTimestamp()); T body = bodyFormat.read(event); Map<String, String> headers = Objects.firstNonNull(event.getHeaders(), ImmutableMap.<String, String>of()); return result.setKey(key).setValue(new GenericStreamEventData<>(headers, body)); } }
format.getSchema(), formatSpec.getSettings()); } catch (UnsupportedTypeException e) { throw new BadRequestException("Format " + formatName + " does not support the requested schema.");
format.initialize(actualSpec); return format;
/** * Initialize the format with the given desired schema and properties. * Guaranteed to be called once before any other method is called. * * @param formatSpecification the specification for the format, containing the desired schema and settings * @throws UnsupportedTypeException if the desired schema and properties are not supported */ public void initialize(@Nullable FormatSpecification formatSpecification) throws UnsupportedTypeException { Schema desiredSchema = null; Map<String, String> settings = Collections.emptyMap(); if (formatSpecification != null) { desiredSchema = formatSpecification.getSchema(); settings = formatSpecification.getSettings(); } desiredSchema = desiredSchema == null ? getDefaultSchema() : desiredSchema; if (desiredSchema == null) { String msg = "A schema must be provided to the format: "; if (formatSpecification != null) { msg += formatSpecification.getName(); } throw new UnsupportedTypeException(msg); } validateIsRecord(desiredSchema); validateSchema(desiredSchema); this.schema = desiredSchema; configure(settings); }