APISonar


org.elasticsearch.xpack.sql.type.DataType.DATE

> org > elasticsearch > xpack > sql > type > DataType > DATE
org APIs elasticsearch APIs xpack APIs sql APIs type APIs DataType APIs DATE APIs

Example 1
public Literal visitDateEscapedLiteral(DateEscapedLiteralContext ctx) {
        String string = string(ctx.string());
        Location loc = source(ctx);
        // parse yyyy-MM-dd
        DateTime dt = null;
        try {
            dt = ISODateTimeFormat.date().parseDateTime(string);
        } catch(IllegalArgumentException ex) {
            throw new ParsingException(loc, "Invalid date received; {}", ex.getMessage());
        }
        return new Literal(loc, DateUtils.of(dt), DataType.DATE);
    }
Example 2
public CurrentDateTime(Location location, Expression precision, Configuration configuration) {
        super(location, configuration, DataType.DATE);
        this.precision = precision;
        int p = precision != null ? ((Number) precision.fold()).intValue() : 0;
        this.dateTime = nanoPrecision(configuration().now(), p);
    }
Example 3
public void collectFields(SqlSourceBuilder sourceBuilder) {
        // nested fields are handled by inner hits
        if (hitName != null) {
            return;
        }
        if (docValue) {
            String format = dataType == DataType.DATE ? "epoch_millis" : null;
            sourceBuilder.addDocField(name, format);
        } else {
            sourceBuilder.addSourceField(name);
        }
    }
Example 4
public void testGroupByHistogram() {
        LogicalPlan p = plan("SELECT MAX(int) FROM test GROUP BY HISTOGRAM(date, INTERVAL 2 YEARS)");
        assertTrue(p instanceof Aggregate);
        Aggregate a = (Aggregate) p;
        List<Expression> groupings = a.groupings();
        assertEquals(1, groupings.size());
        Expression exp = groupings.get(0);
        assertEquals(Histogram.class, exp.getClass());
        Histogram h = (Histogram) exp;
        assertEquals("+2-0", h.interval().fold().toString());
        Expression field = h.field();
        assertEquals(FieldAttribute.class, field.getClass());
        assertEquals(DataType.DATE, field.dataType());
    }
Example 5
public void testGetDate() {
        long millis = 1526467911780L;
        List<Object> documentFieldValues = Collections.singletonList(Long.toString(millis));
        SearchHit hit = new SearchHit(1);
        DocumentField field = new DocumentField("my_date_field", documentFieldValues);
        hit.fields(singletonMap("my_date_field", field));
        FieldHitExtractor extractor = new FieldHitExtractor("my_date_field", DataType.DATE, true);
        assertEquals(DateUtils.of(millis), extractor.extract(hit));
    }
Example 6
public void testTimestampLiteral() {
        Literal l = timestampLiteral("2012-01-01 10:01:02.3456");
        assertThat(l.dataType(), is(DataType.DATE));
    }
Example 7
protected TypeResolution resolveType() {
        TypeResolution resolution = Expressions.typeMustBeNumericOrDate(field(), "HISTOGRAM", ParamOrdinal.FIRST);
        if (resolution == TypeResolution.TYPE_RESOLVED) {
            // interval must be Literal interval
            if (field().dataType() == DataType.DATE) {
                resolution = Expressions.typeMustBe(interval, DataTypes::isInterval, "(Date) HISTOGRAM", ParamOrdinal.SECOND, "interval");
            } else {
                resolution = Expressions.typeMustBeNumeric(interval, "(Numeric) HISTOGRAM", ParamOrdinal.SECOND);
            }
        }

        return resolution;
    }
Example 8
private Tuple<QueryContainer, FieldExtraction> nestedHitFieldRef(FieldAttribute attr) {
        // Find the nested query for this field. If there isn't one then create it
        List<FieldExtraction> nestedRefs = new ArrayList<>();

        String name = aliasName(attr);
        String format = attr.field().getDataType() == DataType.DATE ? "epoch_millis" : DocValueFieldsContext.USE_DEFAULT_FORMAT;
        Query q = rewriteToContainNestedField(query, attr.location(),
                attr.nestedParent().name(), name, format, attr.field().isAggregatable());

        SearchHitFieldRef nestedFieldRef = new SearchHitFieldRef(name, attr.field().getDataType(),
                attr.field().isAggregatable(), attr.parent().name());
        nestedRefs.add(nestedFieldRef);

        return new Tuple<>(new QueryContainer(q, aggs, columns, aliases, pseudoFunctions, scalarFunctions, sort, limit), nestedFieldRef);
    }