Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
LakshSingla committed Oct 5, 2023
1 parent 30cf76d commit db2ac3a
Show file tree
Hide file tree
Showing 7 changed files with 649 additions and 360 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2005,7 +2005,8 @@ private static Pair<List<DimensionSchema>, List<AggregatorFactory>> makeDimensio
DimensionSchemaUtils.createDimensionSchema(
outputColumnName,
type,
MultiStageQueryContext.useAutoColumnSchemas(query.context())
MultiStageQueryContext.useAutoColumnSchemas(query.context()),
MultiStageQueryContext.isIngestStringArraysAsMVDs(query.context())
)
);
} else if (!isRollupQuery) {
Expand Down Expand Up @@ -2054,7 +2055,8 @@ private static void populateDimensionsAndAggregators(
DimensionSchemaUtils.createDimensionSchema(
outputColumn,
type,
MultiStageQueryContext.useAutoColumnSchemas(context)
MultiStageQueryContext.useAutoColumnSchemas(context),
MultiStageQueryContext.isIngestStringArraysAsMVDs(context)
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ private static Iterator<SegmentWithDescriptor> inputSourceSegmentIterator(
DimensionSchemaUtils.createDimensionSchema(
column,
signature.getColumnType(column).orElse(null),
false,
false
)
).collect(Collectors.toList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ public class DimensionSchemaUtils
public static DimensionSchema createDimensionSchema(
final String column,
@Nullable final ColumnType type,
boolean useAutoType
boolean useAutoType,
boolean writeStringArraysAsMVDs
)
{
if (useAutoType) {
// for complex types that are not COMPLEX<json>, we still want to use the handler since 'auto' typing
// only works for the 'standard' built-in typesg
// only works for the 'standard' built-in types
if (type != null && type.is(ValueType.COMPLEX) && !ColumnType.NESTED_DATA.equals(type)) {
final ColumnCapabilities capabilities = ColumnCapabilitiesImpl.createDefault().setType(type);
return DimensionHandlerUtils.getHandlerFromCapabilities(column, capabilities, null)
Expand All @@ -57,7 +58,7 @@ public static DimensionSchema createDimensionSchema(

return new AutoTypeColumnSchema(column);
} else {
// if schema information not available, create a string dimension
// if schema information is not available, create a string dimension
if (type == null) {
return new StringDimensionSchema(column);
}
Expand All @@ -74,7 +75,11 @@ public static DimensionSchema createDimensionSchema(
case ARRAY:
switch (type.getElementType().getType()) {
case STRING:
return new StringDimensionSchema(column, DimensionSchema.MultiValueHandling.ARRAY, null);
if (writeStringArraysAsMVDs) {
return new StringDimensionSchema(column, DimensionSchema.MultiValueHandling.ARRAY, null);
} else {
return new AutoTypeColumnSchema(column);
}
case LONG:
case FLOAT:
case DOUBLE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
* {@link org.apache.druid.segment.AutoTypeColumnSchema} for all 'standard' type columns during segment generation,
* see {@link DimensionSchemaUtils#createDimensionSchema} for more details.
*
* <li><b>ingestStringArraysAsMVDs</b>: Flag to ingest the string arrays using string dimension handlers, which generates
* MVDs instead of {@code ARRAY<STRING>}. The flag is undocumented, and provided to preserve legacy behaviour.
* see {@link DimensionSchemaUtils#createDimensionSchema} for more details.
*
* </ol>
**/
public class MultiStageQueryContext
Expand Down Expand Up @@ -121,6 +125,11 @@ public class MultiStageQueryContext
public static final String CTX_INDEX_SPEC = "indexSpec";

public static final String CTX_USE_AUTO_SCHEMAS = "useAutoColumnSchemas";
public static final boolean DEFAULT_USE_AUTO_SCHEMAS = false;

public static final String CTX_INGEST_STRING_ARRAYS_AS_MVDS = "ingestStringArraysAsMVDs";
public static final boolean DEFAULT_INGEST_STRING_ARRAYS_AS_MVDS = false;


private static final Pattern LOOKS_LIKE_JSON_ARRAY = Pattern.compile("^\\s*\\[.*", Pattern.DOTALL);

Expand Down Expand Up @@ -243,7 +252,12 @@ public static IndexSpec getIndexSpec(final QueryContext queryContext, final Obje

public static boolean useAutoColumnSchemas(final QueryContext queryContext)
{
return queryContext.getBoolean(CTX_USE_AUTO_SCHEMAS, false);
return queryContext.getBoolean(CTX_USE_AUTO_SCHEMAS, DEFAULT_USE_AUTO_SCHEMAS);
}

public static boolean isIngestStringArraysAsMVDs(final QueryContext queryContext)
{
return queryContext.getBoolean(CTX_INGEST_STRING_ARRAYS_AS_MVDS, DEFAULT_INGEST_STRING_ARRAYS_AS_MVDS);
}

/**
Expand Down
Loading

0 comments on commit db2ac3a

Please sign in to comment.