ROUND function crashes upon ROUND(integer_val, 0)
Initially, I got informed of a bug report from the community re: ROUND function: https://community.mapd.com/t/round-function-in-custom-expression-for-table-chart-leads-to-core-dump/513
In investigation I ran a simple test case including a table with different numeric datatypes as small integer, integer, decimal and float and was able to reproduce the issue:
mapdql> \d t1
CREATE TABLE t2 (
val1 DECIMAL(8,2),
val2 INTEGER,
val3 FLOAT,
val4 SMALLINT,
val5 SMALLINT)
mapdql> SELECT * FROM t1;
val1|val2|val3|val4|val5
4926.650000|6888|2.234320|32700|0
262.080000|364|15.100900|100|0
165309.380000|1029652|2343.931885|100|0
// Get a list of integers in 0 round
SELECT ROUND(val1, 0) FROM t1;
Thrift: Mon Sep 18 10:26:48 2017 TSocket::write_partial() send() <Host: localhost Port: 9091>Broken pipe
Thrift: Mon Sep 18 10:26:48 2017 TSocket::open() connect() <Host: localhost Port: 9091>Connection refused
Thrift error: connect() failed: Connection refused
Here are calcite logs from mapd server:
E0918 10:26:34.011047 12208 MapDHandler.cpp:2912] Exception: Inconsistent return type for ROUND
F0918 10:26:42.221366 12208 ExtensionsIR.cpp:64] Check failed: ret_ti.is_integer() || ret_ti.is_fp()
*** Check failure stack trace: ***
@ 0x7fd0081c95cd google::LogMessage::Fail()
@ 0x7fd0081cb433 google::LogMessage::SendToLog()
@ 0x7fd0081c915b google::LogMessage::Flush()
@ 0x7fd0081cbe1e google::LogMessageFatal::~LogMessageFatal()
@ 0x1924265 Executor::codegenFunctionOper()
@ 0x18dc829 Executor::codegen()
@ 0x160b3e2 GroupByAndAggregate::codegenAggArg()
@ 0x1606ddd _ZN19GroupByAndAggregate15codegenAggCallsERKSt5tupleIJPN4llvm5ValueES3_EERKSt6vectorIS3_SaIS3_EERK18CompilationOptions
@ 0x1601e26 GroupByAndAggregate::codegen()
@ 0x16577db Executor::compileWorkUnit()
@ 0x15c7591 Executor::ExecutionDispatch::compile()
@ 0x1538b39 Executor::executeWorkUnit()
@ 0x16efd15 RelAlgExecutor::executeWorkUnit()
@ 0x16ed782 RelAlgExecutor::executeProject()
@ 0x16e8164 RelAlgExecutor::executeRelAlgStep()
@ 0x16e677e RelAlgExecutor::executeRelAlgSeq()
@ 0x16e508d RelAlgExecutor::executeRelAlgQueryNoRetry()
@ 0x16e4a00 RelAlgExecutor::executeRelAlgQuery()
@ 0x13c214f _ZZNK11MapDHandler15execute_rel_algER12TQueryResultRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEbRKN17Catalog_Namespace11SessionInfoE18ExecutorDeviceTypeibbENKUlvE_clEv
@ 0x13c8e94 _ZN7measureINSt6chrono8durationIlSt5ratioILl1ELl1000EEEEE9executionIZNK11MapDHandler15execute_rel_algER12TQueryResultRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEbRKN17Catalog_Namespace11SessionInfoE18ExecutorDeviceTypeibbEUlvE_JEEElT_DpOT0_
@ 0x13c2626 MapDHandler::execute_rel_alg()
@ 0x13c439b MapDHandler::sql_execute_impl()
@ 0x13b2f98 _ZZN11MapDHandler11sql_executeER12TQueryResultRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES9_bS9_iENKUlvE0_clEv
@ 0x13c8a06 _ZN7measureINSt6chrono8durationIlSt5ratioILl1ELl1000EEEEE9executionIZN11MapDHandler11sql_executeER12TQueryResultRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESH_bSH_iEUlvE0_JEEElT_DpOT0_
@ 0x13b324b MapDHandler::sql_execute()
@ 0x13206e1 MapDProcessor::process_sql_execute()
@ 0x13177b9 MapDProcessor::dispatchCall()
@ 0x12c367c apache::thrift::TDispatchProcessor::process()
@ 0x7fd006238512 apache::thrift::server::TConnectedClient::run()
@ 0x7fd006204a94 apache::thrift::concurrency::ThreadManager::Worker::run()
@ 0x7fd006244783 apache::thrift::concurrency::PthreadThread::threadMain()
@ 0x7fd007da46ba start_thread
../startmapd: line 102: 12172 Aborted (core dumped) ./bin/mapd_server $MAPD_DATA $RO --port $MAPD_TCP_PORT --http-port $MAPD_HTTP_PORT --calcite-port $MAPD_CALCITE_PORT $*
I will continually run different test cases and add comments soon.
I know what's going on, the ROUND implementation in QueryEngine/ExtensionFunctions.hpp is not correct. The arity is incorrect, also it cannot be fully implemented as an extension since the return type depends on the input. We have to handle it more like CEIL / FLOOR / TRUNCATE than an extension function.
Commit 6f2730e5a5027b5d37eedbbf65c244e700c76436 avoids the crash, the server reports that the ROUND function is not supported yet, which is actually true.
Filed https://github.com/mapd/mapd-core/issues/73 instead.