Skip to content

Commit cce2982

Browse files
committed
WIP
1 parent 855768c commit cce2982

File tree

6 files changed

+117
-37
lines changed

6 files changed

+117
-37
lines changed

common/src/main/java/org/apache/drill/common/types/Types.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import org.apache.drill.common.types.TypeProtos.DataMode;
2323
import org.apache.drill.common.types.TypeProtos.MajorType;
2424
import org.apache.drill.common.types.TypeProtos.MinorType;
25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
2527

2628
import java.util.ArrayList;
2729
import java.util.Arrays;
@@ -31,7 +33,7 @@
3133
import static org.apache.drill.common.types.TypeProtos.DataMode.REPEATED;
3234

3335
public class Types {
34-
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Types.class);
36+
private static final Logger logger = LoggerFactory.getLogger(Types.class);
3537

3638
public static final int MAX_VARCHAR_LENGTH = 65535;
3739
public static final int DEFAULT_TIMESTAMP_PRECISION = 3;

exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionConverter.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,11 @@
1717
*/
1818
package org.apache.drill.exec.expr.fn;
1919

20-
import java.lang.annotation.Annotation;
21-
import java.lang.reflect.Field;
22-
import java.util.Arrays;
23-
import java.util.List;
24-
25-
import javax.inject.Inject;
26-
20+
import com.google.common.base.Joiner;
21+
import com.google.common.collect.Lists;
2722
import org.apache.drill.common.exceptions.DrillRuntimeException;
28-
import org.apache.drill.common.scanner.persistence.FieldDescriptor;
2923
import org.apache.drill.common.scanner.persistence.AnnotatedClassDescriptor;
24+
import org.apache.drill.common.scanner.persistence.FieldDescriptor;
3025
import org.apache.drill.common.types.TypeProtos.MajorType;
3126
import org.apache.drill.exec.expr.DrillFunc;
3227
import org.apache.drill.exec.expr.annotations.FunctionTemplate;
@@ -38,12 +33,15 @@
3833
import org.apache.drill.exec.ops.UdfUtilities;
3934
import org.apache.drill.exec.vector.complex.reader.FieldReader;
4035
import org.apache.drill.exec.vector.complex.writer.BaseWriter.ComplexWriter;
41-
42-
import com.google.common.base.Joiner;
43-
import com.google.common.collect.Lists;
4436
import org.slf4j.Logger;
4537
import org.slf4j.LoggerFactory;
4638

39+
import javax.inject.Inject;
40+
import java.lang.annotation.Annotation;
41+
import java.lang.reflect.Field;
42+
import java.util.Arrays;
43+
import java.util.List;
44+
4745
/**
4846
* Converts FunctionCalls to Java Expressions.
4947
*/
@@ -100,11 +98,11 @@ public DrillFuncHolder getHolder(AnnotatedClassDescriptor func, ClassLoader clas
10098
fieldClass = fieldClass.getComponentType();
10199
varArgsCount++;
102100
} else if (varArgsCount > 0 && param != null) {
103-
return failure("Vararg should be the last argument in the function.", func, field);
101+
return failure("Vararg should be the last argument in the function {}. Field: {}", func, field);
104102
}
105103

106104
if (varArgsCount > 1) {
107-
return failure("Function should contain single vararg argument", func, field);
105+
return failure("Function {} should contain single vararg argument. Only contains {}", func, field);
108106
}
109107

110108
// Special processing for @Param FieldReader

exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/conversion/SqlConverter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public SqlConverter(QueryContext context) {
120120
.withConformance(DRILL_CONFORMANCE)
121121
.withUnquotedCasing(Casing.UNCHANGED)
122122
.withQuotedCasing(Casing.UNCHANGED);
123+
// TODO Should we add more of these optimizations?
123124
this.sqlToRelConverterConfig = SqlToRelConverter.config()
124125
.withInSubQueryThreshold((int) settings.getInSubqueryThreshold())
125126
.withRemoveSortInSubQuery(false)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!--
3+
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
20+
-->
21+
<configuration>
22+
<if condition='property("drill.lilith.enable").equalsIgnoreCase("true")'>
23+
<then>
24+
<appender name="SOCKET" class="de.huxhorn.lilith.logback.appender.ClassicMultiplexSocketAppender">
25+
<Compressing>true</Compressing>
26+
<ReconnectionDelay>10000</ReconnectionDelay>
27+
<IncludeCallerData>true</IncludeCallerData>
28+
<RemoteHosts>${LILITH_HOSTNAME:-localhost}</RemoteHosts>
29+
</appender>
30+
31+
<logger name="org.apache.drill" additivity="false">
32+
<level value="DEBUG"/>
33+
<appender-ref ref="SOCKET"/>
34+
</logger>
35+
36+
<logger name="query.logger" additivity="false">
37+
<level value="ERROR"/>
38+
<appender-ref ref="SOCKET"/>
39+
</logger>
40+
<logger name="org.apache.drill.exec.planner">
41+
<level value="DEBUG"/>
42+
<appender-ref ref="SOCKET"/>
43+
</logger>
44+
</then>
45+
</if>
46+
47+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
48+
<!-- encoders are assigned the type
49+
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
50+
<encoder>
51+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
52+
</encoder>
53+
</appender>
54+
55+
<!--<root>
56+
<level value="WARN"/>
57+
<if condition='property("drill.lilith.enable").equalsIgnoreCase("true")'>
58+
<then>
59+
<appender-ref ref="SOCKET"/>
60+
</then>
61+
</if>
62+
<appender-ref ref="STDOUT"/>
63+
</root>-->
64+
<logger name="org.apache.drill.exec.planner" additivity="false">
65+
<level value="debug" />
66+
<appender-ref ref="STDOUT" />
67+
</logger>
68+
69+
</configuration>

exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestCastFunctions.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,17 @@
1717
*/
1818
package org.apache.drill.exec.fn.impl;
1919

20-
import java.math.BigDecimal;
21-
import java.time.LocalDate;
22-
import java.time.LocalDateTime;
23-
import java.time.LocalTime;
24-
import java.util.HashMap;
25-
import java.util.HashSet;
26-
import java.util.List;
27-
import java.util.Map;
28-
import java.util.Set;
29-
20+
import com.google.common.collect.Lists;
21+
import com.google.common.collect.Maps;
3022
import org.apache.drill.categories.SqlFunctionTest;
3123
import org.apache.drill.categories.UnlikelyTest;
3224
import org.apache.drill.common.exceptions.UserRemoteException;
3325
import org.apache.drill.common.types.TypeProtos;
3426
import org.apache.drill.common.types.Types;
3527
import org.apache.drill.exec.planner.physical.PlannerSettings;
3628
import org.apache.drill.exec.record.BatchSchema;
37-
import org.apache.drill.exec.record.MaterializedField;
3829
import org.apache.drill.exec.record.BatchSchemaBuilder;
30+
import org.apache.drill.exec.record.MaterializedField;
3931
import org.apache.drill.exec.record.metadata.SchemaBuilder;
4032
import org.apache.drill.exec.vector.IntervalDayVector;
4133
import org.apache.drill.exec.vector.IntervalYearVector;
@@ -48,8 +40,15 @@
4840
import org.junit.experimental.categories.Category;
4941
import org.junit.rules.ExpectedException;
5042

51-
import com.google.common.collect.Lists;
52-
import com.google.common.collect.Maps;
43+
import java.math.BigDecimal;
44+
import java.time.LocalDate;
45+
import java.time.LocalDateTime;
46+
import java.time.LocalTime;
47+
import java.util.HashMap;
48+
import java.util.HashSet;
49+
import java.util.List;
50+
import java.util.Map;
51+
import java.util.Set;
5352

5453
import static org.apache.drill.common.types.TypeProtos.MinorType.BIGINT;
5554
import static org.apache.drill.common.types.TypeProtos.MinorType.BIT;
@@ -614,9 +613,9 @@ public void testCastNegativeDecimalToVarChar() throws Exception {
614613

615614
@Test
616615
public void testCastDecimalLiteral() throws Exception {
617-
String query =
618-
"select case when true then cast(100.0 as decimal(38,2)) else cast('123.0' as decimal(38,2)) end as c1";
619-
616+
// String query =
617+
// "select case when true then cast(100.0 as decimal(38,2)) else cast('123.0' as decimal(38,2)) end as c1";
618+
String query = "SELECT CAST(100 AS DECIMAL(38,2)) AS c1";
620619
testBuilder()
621620
.sqlQuery(query)
622621
.ordered()
@@ -630,7 +629,7 @@ public void testCastDecimalZeroPrecision() throws Exception {
630629
String query = "select cast('123.0' as decimal(0, 5))";
631630

632631
thrown.expect(UserRemoteException.class);
633-
thrown.expectMessage(containsString("VALIDATION ERROR: Expected precision greater than 0, but was 0"));
632+
thrown.expectMessage(containsString("VALIDATION ERROR: Expected precision greater than 0, but was 0."));
634633

635634
run(query);
636635
}
@@ -640,7 +639,7 @@ public void testCastDecimalGreaterScaleThanPrecision() throws Exception {
640639
String query = "select cast('123.0' as decimal(3, 5))";
641640

642641
thrown.expect(UserRemoteException.class);
643-
thrown.expectMessage(containsString("VALIDATION ERROR: Expected scale less than or equal to precision, but was precision 3 and scale 5"));
642+
thrown.expectMessage(containsString("VALIDATION ERROR: Expected scale less than or equal to precision, but was scale 5 and precision 3."));
644643

645644
run(query);
646645
}

exec/vector/src/main/java/org/apache/drill/exec/util/DecimalUtility.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,15 @@
2121
import io.netty.buffer.ByteBuf;
2222
import io.netty.buffer.DrillBuf;
2323
import io.netty.buffer.UnpooledByteBufAllocator;
24-
25-
import java.math.BigDecimal;
26-
import java.math.BigInteger;
27-
import java.math.RoundingMode;
28-
2924
import org.apache.drill.common.exceptions.UserException;
3025
import org.apache.drill.common.types.TypeProtos;
3126
import org.slf4j.Logger;
3227
import org.slf4j.LoggerFactory;
3328

29+
import java.math.BigDecimal;
30+
import java.math.BigInteger;
31+
import java.math.RoundingMode;
32+
3433
@SuppressWarnings("WeakerAccess")
3534
public class DecimalUtility {
3635

@@ -433,6 +432,18 @@ public static int getDefaultPrecision(TypeProtos.MinorType minorType, int defaul
433432
* @param desiredScale scale for the resulting value
434433
*/
435434
public static void checkValueOverflow(BigDecimal value, int desiredPrecision, int desiredScale) {
435+
if (desiredPrecision < 1) {
436+
throw UserException.validationError()
437+
.message("Expected precision greater than 0, but was %s.", desiredPrecision)
438+
.build(logger);
439+
}
440+
if (desiredScale > desiredPrecision) {
441+
throw UserException.validationError()
442+
.message("Expected scale less than or equal to precision, " +
443+
"but was scale %s and precision %s.", desiredScale, desiredPrecision)
444+
.build(logger);
445+
}
446+
436447
if (value.precision() - value.scale() > desiredPrecision - desiredScale) {
437448
throw UserException.validationError()
438449
.message("Value %s overflows specified precision %s with scale %s.",

0 commit comments

Comments
 (0)