Search in sources :

Example 51 with JsonFactory

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

the class DruidQueryFilterTest method testBetweenFilterStringCase.

@Test
public void testBetweenFilterStringCase() throws IOException {
    final Fixture f = new Fixture();
    final List<RexNode> listRexNodes = ImmutableList.of(f.rexBuilder.makeLiteral(false), f.rexBuilder.makeInputRef(f.varcharRowType, 0), f.rexBuilder.makeLiteral("lower-bound"), f.rexBuilder.makeLiteral("upper-bound"));
    RelDataType relDataType = f.typeFactory.createSqlType(SqlTypeName.BOOLEAN);
    RexNode betweenRexNode = f.rexBuilder.makeCall(relDataType, SqlStdOperatorTable.BETWEEN, listRexNodes);
    DruidJsonFilter returnValue = DruidJsonFilter.toDruidFilters(betweenRexNode, f.varcharRowType, druidQuery);
    Assert.assertNotNull("Filter is null", returnValue);
    JsonFactory jsonFactory = new JsonFactory();
    final StringWriter sw = new StringWriter();
    JsonGenerator jsonGenerator = jsonFactory.createGenerator(sw);
    returnValue.write(jsonGenerator);
    jsonGenerator.close();
    Assert.assertThat(sw.toString(), is("{\"type\":\"bound\",\"dimension\":\"dimensionName\",\"lower\":\"lower-bound\"," + "\"lowerStrict\":false,\"upper\":\"upper-bound\",\"upperStrict\":false," + "\"ordering\":\"lexicographic\"}"));
}
Also used : StringWriter(java.io.StringWriter) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) RelDataType(org.apache.calcite.rel.type.RelDataType) RexNode(org.apache.calcite.rex.RexNode) Test(org.junit.Test)

Example 52 with JsonFactory

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory 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 53 with JsonFactory

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory 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 54 with JsonFactory

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

the class ArtifactoryHttpClient method createJsonFactory.

public JsonFactory createJsonFactory() {
    JsonFactory jsonFactory = new JsonFactory();
    ObjectMapper mapper = new ObjectMapper(jsonFactory);
    mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector());
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    jsonFactory.setCodec(mapper);
    return jsonFactory;
}
Also used : JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) JsonFactory(com.fasterxml.jackson.core.JsonFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 55 with JsonFactory

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory 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)

Aggregations

JsonFactory (com.fasterxml.jackson.core.JsonFactory)266 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)102 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)91 JsonParser (com.fasterxml.jackson.core.JsonParser)78 Test (org.junit.Test)65 IOException (java.io.IOException)62 StringWriter (java.io.StringWriter)60 Map (java.util.Map)27 HashMap (java.util.HashMap)26 ArrayList (java.util.ArrayList)25 JsonNode (com.fasterxml.jackson.databind.JsonNode)21 List (java.util.List)18 ExtensibleJSONWriter (com.instagram.common.json.annotation.processor.support.ExtensibleJSONWriter)16 JsonToken (com.fasterxml.jackson.core.JsonToken)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 File (java.io.File)14 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 InputStreamReader (java.io.InputStreamReader)9 TypeReference (com.fasterxml.jackson.core.type.TypeReference)8 SimpleParseUUT (com.instagram.common.json.annotation.processor.uut.SimpleParseUUT)8