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\"}"));
}
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();
}
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();
}
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;
}
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;
}
Aggregations