[
https://issues.apache.org/jira/browse/DRILL-6361?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16460749#comment-16460749
]
ASF GitHub Bot commented on DRILL-6361:
---------------------------------------
Github user vvysotskyi commented on a diff in the pull request:
https://github.com/apache/drill/pull/1242#discussion_r185435469
--- Diff:
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/UnionFunctions.java
---
@@ -146,16 +139,131 @@ private static int getTypeValue(MinorType type) {
@Inject
DrillBuf buf;
+ @Override
public void setup() {}
+ @Override
public void eval() {
- byte[] type;
+ String typeName;
if (input.isSet()) {
- type = input.getType().getMinorType().name().getBytes();
+ typeName = input.getType().getMinorType().name();
} else {
- type =
org.apache.drill.common.types.TypeProtos.MinorType.NULL.name().getBytes();
+ typeName =
org.apache.drill.common.types.TypeProtos.MinorType.NULL.name();
}
+ byte[] type = typeName.getBytes();
+ buf = buf.reallocIfNeeded(type.length);
+ buf.setBytes(0, type);
+ out.buffer = buf;
+ out.start = 0;
+ out.end = type.length;
+ }
+ }
+
+ @FunctionTemplate(name = "sqlTypeOf",
+ scope = FunctionTemplate.FunctionScope.SIMPLE,
+ nulls = NullHandling.INTERNAL)
+ public static class GetSqlType implements DrillSimpleFunc {
+
+ @Param
+ FieldReader input;
+ @Output
+ VarCharHolder out;
+ @Inject
+ DrillBuf buf;
+
+ @Override
+ public void setup() {}
+
+ @Override
+ public void eval() {
+
+ org.apache.drill.common.types.TypeProtos.MajorType type =
input.getType();
+
+ // Note: extendType is a static function because the byte code magic
+ // for UDFS can't handle switch statements.
+
+ String typeName =
+ org.apache.drill.exec.expr.fn.impl.UnionFunctions.extendType(
+ type,
+
org.apache.drill.common.types.Types.getBaseSqlTypeName(type));
+
+
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.varCharOutput(
--- End diff --
I think passing a holder into the method may prevent scalar replacement for
this holder.
> Provide sqlTypeOf() and modeOf() functions
> ------------------------------------------
>
> Key: DRILL-6361
> URL: https://issues.apache.org/jira/browse/DRILL-6361
> Project: Apache Drill
> Issue Type: Improvement
> Affects Versions: 1.13.0
> Reporter: Paul Rogers
> Assignee: Paul Rogers
> Priority: Minor
> Labels: doc-impacting
>
> Drill provides a {{typeof()}} function to return the type of a column. The
> returned string, however, has only the base data type. A Drill data type (a
> "major type") also includes a cardinality (a "mode"). For example, {{Optional
> Int}} or {{Required VarChar}}.
> This type information is useful for handling data conversions. For example,
> if I could tell that a column value was a {{Nullable Int}}, I could guess
> that it is one Drill invented, and I could merge it, by hand, with the type
> from another file that had actual values.
> The two options are equivalent. Either provide a {{modeOf()}} to just return
> cardinality, or a {{dataTypeOf()}} that returns both. (Maybe the {{modeOf()}}
> might be more useful.)
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)