Search in sources :

Example 86 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project calcite by apache.

the class DruidQuery method planAsTopN.

@Nullable
private String planAsTopN(List<DimensionSpec> groupByKeyDims, DruidJsonFilter jsonFilter, List<VirtualColumn> virtualColumnList, List<JsonAggregation> aggregations, List<JsonExpressionPostAgg> postAggregations, JsonLimit limit, DruidJsonFilter havingFilter) {
    if (havingFilter != null) {
        return null;
    }
    if (!getConnectionConfig().approximateTopN() || groupByKeyDims.size() != 1 || limit.limit == null || limit.collations == null || limit.collations.size() != 1) {
        return null;
    }
    if (limit.collations.get(0).dimension.equals(groupByKeyDims.get(0).getOutputName())) {
        return null;
    }
    if (limit.collations.get(0).direction.equals("ascending")) {
        // Only DESC is allowed
        return null;
    }
    final String topNMetricColumnName = limit.collations.get(0).dimension;
    final StringWriter sw = new StringWriter();
    final JsonFactory factory = new JsonFactory();
    try {
        final JsonGenerator generator = factory.createGenerator(sw);
        generator.writeStartObject();
        generator.writeStringField("queryType", "topN");
        generator.writeStringField("dataSource", druidTable.dataSource);
        writeField(generator, "granularity", Granularities.all());
        writeField(generator, "dimension", groupByKeyDims.get(0));
        writeFieldIf(generator, "virtualColumns", virtualColumnList.size() > 0 ? virtualColumnList : null);
        generator.writeStringField("metric", topNMetricColumnName);
        writeFieldIf(generator, "filter", jsonFilter);
        writeField(generator, "aggregations", aggregations);
        writeFieldIf(generator, "postAggregations", postAggregations.size() > 0 ? postAggregations : null);
        writeField(generator, "intervals", intervals);
        generator.writeNumberField("threshold", limit.limit);
        generator.writeEndObject();
        generator.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return sw.toString();
}
Also used : StringWriter(java.io.StringWriter) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException) Nullable(javax.annotation.Nullable)

Example 87 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project calcite by apache.

the class DruidQuery method metadataQuery.

/**
 * Generates a JSON string to query metadata about a data source.
 */
static String metadataQuery(String dataSourceName, List<Interval> intervals) {
    final StringWriter sw = new StringWriter();
    final JsonFactory factory = new JsonFactory();
    try {
        final JsonGenerator generator = factory.createGenerator(sw);
        generator.writeStartObject();
        generator.writeStringField("queryType", "segmentMetadata");
        generator.writeStringField("dataSource", dataSourceName);
        generator.writeBooleanField("merge", true);
        generator.writeBooleanField("lenientAggregatorMerge", true);
        generator.writeArrayFieldStart("analysisTypes");
        generator.writeString("aggregators");
        generator.writeEndArray();
        writeFieldIf(generator, "intervals", intervals);
        generator.writeEndObject();
        generator.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return sw.toString();
}
Also used : StringWriter(java.io.StringWriter) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException)

Example 88 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project build-info by JFrogDev.

the class BuildInfoExtractorUtils method buildInfoToJsonString.

public static <T extends Serializable> String buildInfoToJsonString(T buildComponent) throws IOException {
    JsonFactory jsonFactory = createJsonFactory();
    StringWriter writer = new StringWriter();
    JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(writer);
    jsonGenerator.useDefaultPrettyPrinter();
    jsonGenerator.writeObject(buildComponent);
    String result = writer.getBuffer().toString();
    return result;
}
Also used : JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator)

Example 89 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project build-info by JFrogDev.

the class BuildInfoExtractorUtils method buildInfoToJsonString.

public static String buildInfoToJsonString(Build buildInfo) throws IOException {
    JsonFactory jsonFactory = createJsonFactory();
    StringWriter writer = new StringWriter();
    JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(writer);
    jsonGenerator.useDefaultPrettyPrinter();
    jsonGenerator.writeObject(buildInfo);
    String result = writer.getBuffer().toString();
    return result;
}
Also used : JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator)

Example 90 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project rpki-validator-3 by RIPE-NCC.

the class ApiConfig method customizeLinksRendering.

@Bean
public Jackson2ObjectMapperBuilderCustomizer customizeLinksRendering() {
    return (jacksonObjectMapperBuilder) -> {
        jacksonObjectMapperBuilder.serializerByType(Links.class, new JsonObjectSerializer<Links>() {

            @Override
            protected void serializeObject(Links value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
                for (Link link : value) {
                    jgen.writeStringField(link.getRel(), link.getHref());
                }
            }
        });
        jacksonObjectMapperBuilder.deserializerByType(Links.class, new JsonObjectDeserializer<Links>() {

            @Override
            protected Links deserializeObject(JsonParser jsonParser, DeserializationContext context, ObjectCodec codec, JsonNode tree) throws IOException {
                Iterator<Map.Entry<String, JsonNode>> iterator = tree.fields();
                List<Link> links = new ArrayList<>();
                while (iterator.hasNext()) {
                    Map.Entry<String, JsonNode> field = iterator.next();
                    links.add(new Link(field.getValue().asText(), field.getKey()));
                }
                return new Links(links);
            }
        });
    };
}
Also used : Jackson2ObjectMapperBuilderCustomizer(org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer) Link(org.springframework.hateoas.Link) java.util(java.util) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) JsonParser(com.fasterxml.jackson.core.JsonParser) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) Links(org.springframework.hateoas.Links) MediaType(org.springframework.http.MediaType) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec) IOException(java.io.IOException) Configuration(org.springframework.context.annotation.Configuration) Api(net.ripe.rpki.rtr.api.Api) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) JsonObjectDeserializer(org.springframework.boot.jackson.JsonObjectDeserializer) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonObjectSerializer(org.springframework.boot.jackson.JsonObjectSerializer) ContentNegotiationConfigurer(org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer) SerializerProvider(com.fasterxml.jackson.databind.SerializerProvider) Bean(org.springframework.context.annotation.Bean) WebMvcConfigurer(org.springframework.web.servlet.config.annotation.WebMvcConfigurer) JsonObjectSerializer(org.springframework.boot.jackson.JsonObjectSerializer) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec) JsonObjectDeserializer(org.springframework.boot.jackson.JsonObjectDeserializer) Links(org.springframework.hateoas.Links) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) SerializerProvider(com.fasterxml.jackson.databind.SerializerProvider) Link(org.springframework.hateoas.Link) JsonParser(com.fasterxml.jackson.core.JsonParser) Bean(org.springframework.context.annotation.Bean)

Aggregations

JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)704 KriptonJsonContext (com.abubusoft.kripton.KriptonJsonContext)257 KriptonByteArrayOutputStream (com.abubusoft.kripton.common.KriptonByteArrayOutputStream)257 KriptonRuntimeException (com.abubusoft.kripton.exception.KriptonRuntimeException)257 JacksonWrapperSerializer (com.abubusoft.kripton.persistence.JacksonWrapperSerializer)257 IOException (java.io.IOException)169 StringWriter (java.io.StringWriter)144 JsonFactory (com.fasterxml.jackson.core.JsonFactory)101 ByteArrayOutputStream (java.io.ByteArrayOutputStream)66 Map (java.util.Map)57 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)54 HashMap (java.util.HashMap)40 Test (org.junit.Test)30 File (java.io.File)27 ArrayList (java.util.ArrayList)25 OutputStream (java.io.OutputStream)24 Writer (java.io.Writer)22 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)21 SerializerProvider (com.fasterxml.jackson.databind.SerializerProvider)20 FileOutputStream (java.io.FileOutputStream)19