Tabnine Logo
GranularityType
Code IndexAdd Tabnine to your IDE (free)

How to use
GranularityType
in
org.apache.druid.java.util.common.granularity

Best Java code snippets using org.apache.druid.java.util.common.granularity.GranularityType (Showing top 17 results out of 315)

origin: apache/incubator-druid

@Override
public DateTimeFormatter getFormatter(Formatter type)
{
 GranularityType granularityType = GranularityType.fromPeriod(period);
 switch (type) {
  case DEFAULT:
   return DateTimeFormat.forPattern(granularityType.getDefaultFormat());
  case HIVE:
   return DateTimeFormat.forPattern(granularityType.getHiveFormat());
  case LOWER_DEFAULT:
   return DateTimeFormat.forPattern(granularityType.getLowerDefaultFormat());
  default:
   throw new IAE("There is no format for type %s", type);
 }
}
origin: apache/incubator-druid

/**
 * For a select subset of granularites, users can specify them directly as string.
 * These are "predefined granularities" or "standard" granularities.
 * For all others, the users will have to use "Duration" or "Period" type granularities
 */
public static boolean isStandard(Granularity granularity)
{
 final GranularityType[] values = GranularityType.values();
 for (GranularityType value : values) {
  if (value.getDefaultGranularity().equals(granularity)) {
   return true;
  }
 }
 return false;
}
origin: apache/incubator-druid

@Override
public DateTime toDate(String filePath, Formatter formatter)
{
 Integer[] vals = getDateValues(filePath, formatter);
 GranularityType granularityType = GranularityType.fromPeriod(period);
 DateTime date = granularityType.getDateTime(vals);
 if (date != null) {
  return bucketStart(date);
 }
 return null;
}
origin: apache/incubator-druid

GranularityType(GranularityType granularityType, String period)
{
 this(
   granularityType.getHiveFormat(),
   granularityType.getLowerDefaultFormat(),
   granularityType.getDefaultFormat(),
   granularityType.dateValuePositions,
   period
 );
}
origin: apache/incubator-druid

@Override
public void serialize(JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
  throws IOException
{
 // Retain the same behavior as before #3850.
 // i.e. when Granularity class was an enum.
 if (GranularityType.isStandard(this)) {
  jsonGenerator.writeString(GranularityType.fromPeriod(getPeriod()).toString());
 } else {
  jsonGenerator.writeStartObject();
  jsonGenerator.writeStringField("type", "period");
  jsonGenerator.writeObjectField("period", getPeriod());
  jsonGenerator.writeObjectField("timeZone", getTimeZone());
  jsonGenerator.writeObjectField("origin", getOrigin());
  jsonGenerator.writeEndObject();
 }
}
origin: apache/incubator-druid

  dimensionsSpec,
  metricsSpec,
  GranularityType.fromPeriod(interval.toPeriod()).getDefaultGranularity(),
  jsonMapper
);
origin: apache/incubator-druid

for (GranularityType granularityType : GranularityType.values()) {
 final Granularity granularity = granularityType.getDefaultGranularity();
   mapper.readValue("\"" + StringUtils.toUpperCase(granularityType.name()) + "\"", Granularity.class)
 );
   mapper.readValue("\"" + StringUtils.toLowerCase(granularityType.name()) + "\"", Granularity.class)
 );
    "{\"type\":\"" + StringUtils.toLowerCase(granularityType.name()) + "\"}",
    mapper.writeValueAsString(granularity)
  );
 } else {
  Assert.assertEquals(
    "\"" + StringUtils.toUpperCase(granularityType.name()) + "\"",
    mapper.writeValueAsString(granularity)
  );
origin: apache/incubator-druid

@JsonCreator
public static Granularity fromString(String str)
{
 return GranularityType.valueOf(StringUtils.toUpperCase(str)).getDefaultGranularity();
}
origin: apache/incubator-druid

public static List<Granularity> granularitiesFinerThan(final Granularity gran0)
{
 final List<Granularity> retVal = new ArrayList<>();
 final DateTime origin = (gran0 instanceof PeriodGranularity) ? ((PeriodGranularity) gran0).getOrigin() : null;
 final DateTimeZone tz = (gran0 instanceof PeriodGranularity) ? ((PeriodGranularity) gran0).getTimeZone() : null;
 for (GranularityType gran : GranularityType.values()) {
  /**
   * All and None are excluded b/c when asked to give all granularities finer
   * than "TEN_MINUTE", you want the answer to be "FIVE_MINUTE, MINUTE and SECOND"
   * it doesn't make sense to include ALL or None to be part of this.
   */
  if (gran == GranularityType.ALL || gran == GranularityType.NONE) {
   continue;
  }
  final Granularity segmentGranularity = gran.create(origin, tz);
  final long segmentGranularityDurationMillis = segmentGranularity.bucket(DateTimes.EPOCH).toDurationMillis();
  final long gran0DurationMillis = gran0.bucket(DateTimes.EPOCH).toDurationMillis();
  if (segmentGranularityDurationMillis <= gran0DurationMillis) {
   retVal.add(segmentGranularity);
  }
 }
 retVal.sort((g1, g2) -> {
  long duration1 = g2.bucket(DateTimes.EPOCH).toDurationMillis();
  long duration2 = g1.bucket(DateTimes.EPOCH).toDurationMillis();
  return Longs.compare(duration1, duration2);
 });
 return retVal;
}
origin: apache/incubator-druid

@Test
public void testCustomNestedPeriodFail()
{
 try {
  Period p = Period.years(6).withMonths(3).withSeconds(23);
  GranularityType.fromPeriod(p);
  Assert.fail("Complicated period creation should fail b/c of unsupported granularity type.");
 }
 catch (IAE e) {
  // pass
 }
}
origin: org.apache.druid/java-util

@Override
public void serialize(
  JsonGenerator jsonGenerator, SerializerProvider serializerProvider
) throws IOException, JsonProcessingException
{
 // Retain the same behavior as before #3850.
 // i.e. when Granularity class was an enum.
 if (GranularityType.isStandard(this)) {
  jsonGenerator.writeString(GranularityType.fromPeriod(getPeriod()).toString());
 } else {
  jsonGenerator.writeStartObject();
  jsonGenerator.writeStringField("type", "period");
  jsonGenerator.writeObjectField("period", getPeriod());
  jsonGenerator.writeObjectField("timeZone", getTimeZone());
  jsonGenerator.writeObjectField("origin", getOrigin());
  jsonGenerator.writeEndObject();
 }
}
origin: org.apache.druid/java-util

GranularityType(GranularityType granularityType, String period)
{
 this(
   granularityType.getHiveFormat(),
   granularityType.getLowerDefaultFormat(),
   granularityType.getDefaultFormat(),
   granularityType.dateValuePositions,
   period
 );
}
origin: org.apache.druid/java-util

@JsonCreator
public static Granularity fromString(String str)
{
 return GranularityType.valueOf(StringUtils.toUpperCase(str)).getDefaultGranularity();
}
origin: org.apache.druid/java-util

public static List<Granularity> granularitiesFinerThan(final Granularity gran0)
{
 final List<Granularity> retVal = Lists.newArrayList();
 final DateTime origin = (gran0 instanceof PeriodGranularity) ? ((PeriodGranularity) gran0).getOrigin() : null;
 final DateTimeZone tz = (gran0 instanceof PeriodGranularity) ? ((PeriodGranularity) gran0).getTimeZone() : null;
 for (GranularityType gran : GranularityType.values()) {
  /**
   * All and None are excluded b/c when asked to give all granularities finer
   * than "TEN_MINUTE", you want the answer to be "FIVE_MINUTE, MINUTE and SECOND"
   * it doesn't make sense to include ALL or None to be part of this.
   */
  if (gran == GranularityType.ALL || gran == GranularityType.NONE) {
   continue;
  }
  final Granularity segmentGranularity = gran.create(origin, tz);
  final long segmentGranularityDurationMillis = segmentGranularity.bucket(DateTimes.EPOCH).toDurationMillis();
  final long gran0DurationMillis = gran0.bucket(DateTimes.EPOCH).toDurationMillis();
  if (segmentGranularityDurationMillis <= gran0DurationMillis) {
   retVal.add(segmentGranularity);
  }
 }
 retVal.sort((g1, g2) -> {
  long duration1 = g2.bucket(DateTimes.EPOCH).toDurationMillis();
  long duration2 = g1.bucket(DateTimes.EPOCH).toDurationMillis();
  return Longs.compare(duration1, duration2);
 });
 return retVal;
}
origin: org.apache.druid/java-util

@Override
public DateTimeFormatter getFormatter(Formatter type)
{
 GranularityType granularityType = GranularityType.fromPeriod(period);
 switch (type) {
  case DEFAULT:
   return DateTimeFormat.forPattern(granularityType.getDefaultFormat());
  case HIVE:
   return DateTimeFormat.forPattern(granularityType.getHiveFormat());
  case LOWER_DEFAULT:
   return DateTimeFormat.forPattern(granularityType.getLowerDefaultFormat());
  default:
   throw new IAE("There is no format for type %s", type);
 }
}
origin: org.apache.druid/java-util

/**
 * For a select subset of granularites, users can specify them directly as string.
 * These are "predefined granularities" or "standard" granularities.
 * For all others, the users will have to use "Duration" or "Period" type granularities
 */
public static boolean isStandard(Granularity granularity)
{
 final GranularityType[] values = GranularityType.values();
 for (GranularityType value : values) {
  if (value.getDefaultGranularity().equals(granularity)) {
   return true;
  }
 }
 return false;
}
origin: org.apache.druid/java-util

@Override
public DateTime toDate(String filePath, Formatter formatter)
{
 Integer[] vals = getDateValues(filePath, formatter);
 GranularityType granularityType = GranularityType.fromPeriod(period);
 DateTime date = granularityType.getDateTime(vals);
 if (date != null) {
  return bucketStart(date);
 }
 return null;
}
org.apache.druid.java.util.common.granularityGranularityType

Javadoc

Only to create a mapping of the granularity and all the supported file patterns namely: default, lowerDefault and hive.

Most used methods

  • fromPeriod
    Note: This is only an estimate based on the values in period. This will not work for complicated per
  • getDefaultGranularity
  • values
  • create
  • getDateTime
  • getDefaultFormat
  • getHiveFormat
  • getLowerDefaultFormat
  • isStandard
    For a select subset of granularites, users can specify them directly as string. These are "predefine
  • toString
  • valueOf
  • name
  • valueOf,
  • name

Popular in Java

  • Creating JSON documents from java classes using gson
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • getSharedPreferences (Context)
  • IOException (java.io)
    Signals a general, I/O-related error. Error details may be specified when calling the constructor, a
  • DecimalFormat (java.text)
    A concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features desig
  • HashSet (java.util)
    HashSet is an implementation of a Set. All optional operations (adding and removing) are supported.
  • ZipFile (java.util.zip)
    This class provides random read access to a zip file. You pay more to read the zip file's central di
  • DataSource (javax.sql)
    An interface for the creation of Connection objects which represent a connection to a database. This
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now