I am using Datetime in Kusto. What should be the data type in Java to ingest to Kusto as datetime?
Example: I am setting StartTime:datetime, EndTime: datetime as column type. I have tried Date as type in java but Kusto is not accepting this type:
import java.util.Date;
public Date startTime;
public Date endTime;
What should be the type instead?
tl;dr
Likely
OffsetDateTime, or elseInstant.Kusto
datetimeIn Kusto, the
datetimedata type represents a moment as seen in UTC, that is, a date and time-of-day with an offset from UTC of zero hours-minutes-seconds. Thedatetimetype resolves to 100-nanosecond units.java.time.InstantIn Java, the
Instantclass represents a moment as seen in UTC. This type has a finer resolution, down to nanoseconds.So, the
Instantclass in Java is the natural counterpart todatetimein Kusto.java.time.OffsetDateTimeHowever, your Java driver for Kusto may use another type, if it abides by the JDBC specification. JDBC is oriented to the SQL standard. Per that standard, the Java class
OffsetDateTimeis mapped to columns of a type akin to the SQL standard typeTIMESTAMP WITH TIME ZONE.An
OffsetDateTimeis similar toInstantin that in represents a date and time-of-day as seen in a particular offset from UTC. InOffsetDateTime, the offset can be any number of hours-minutes-seconds whereas inInstantthe offset is always zero.Also,
Instantis the basic building-block class within the java.time framework. In contrast,OffsetDateTimeis more flexible including more options for parsing & generating text representations.I am not a Kusto user, and their documentation is lacking, so I do not know which Java class your driver will map to a Kusto
datetime. But I would guess mostly likely anOffsetDateTime, or otherwise anInstant.Conversion
You can easily convert between the two.
… and:
Avoid legacy date-time classes
Be aware that
java.util.Dateshown in your Question is one of the terribly flawed date-time classes from the earliest versions of Java. These legacy classes were years ago supplanted entirely by the modern java.time classes defined in JSR 310 for Java 8+.