import logging
import pytest
from copy import copy
from tests.common.test_vector import *
from tests.common.impala_test_suite import *

class TestDecimalQueries(ImpalaTestSuite):
  BATCH_SIZES = [0, 1]

  @classmethod
  def get_workload(cls):
    return 'functional-query'

  @classmethod
  def add_test_dimensions(cls):
    super(TestDecimalQueries, cls).add_test_dimensions()
    cls.TestMatrix.add_dimension(
        TestDimension('batch_size', *TestDecimalQueries.BATCH_SIZES))

    # On CDH4, hive does not support decimal so we can't run these tests against
    # the other file formats. Enable them on C5.
    cls.TestMatrix.add_constraint(lambda v:\
        (v.get_value('table_format').file_format == 'text' and
         v.get_value('table_format').compression_codec == 'none') or
         v.get_value('table_format').file_format == 'parquet')

  def test_queries(self, vector):
    new_vector = copy(vector)
    new_vector.get_value('exec_option')['batch_size'] = vector.get_value('batch_size')
    self.run_test_case('QueryTest/decimal', new_vector)


import logging
import pytest
from copy import copy
from tests.common.test_vector import *
from tests.common.impala_test_suite import *

class TestDecimalQueries(ImpalaTestSuite):
  BATCH_SIZES = [0, 1]

  @classmethod
  def get_workload(cls):
    return 'functional-query'

  @classmethod
  def add_test_dimensions(cls):
    super(TestDecimalQueries, cls).add_test_dimensions()
    cls.TestMatrix.add_dimension(
        TestDimension('batch_size', *TestDecimalQueries.BATCH_SIZES))

    # On CDH4, hive does not support decimal so we can't run these tests against
    # the other file formats. Enable them on C5.
    cls.TestMatrix.add_constraint(lambda v:\
        (v.get_value('table_format').file_format == 'text' and
         v.get_value('table_format').compression_codec == 'none') or
         v.get_value('table_format').file_format == 'parquet')

  def test_queries(self, vector):
    if os.environ.get('ASAN_OPTIONS') == 'handle_segv=0':
      pytest.xfail(reason="IMPALA-959: Sum on a decimal column fails ASAN")
    new_vector = copy(vector)
    new_vector.get_value('exec_option')['batch_size'] = vector.get_value('batch_size')
    self.run_test_case('QueryTest/decimal', new_vector)


Fix the ASAN build by xfailing test_decimal when ASAN_OPTIONS is set.
Fix the ASAN build by xfailing test_decimal when ASAN_OPTIONS is set.

Adding decimal columns crashes an ASAN built impalad. This change skips the test.

Change-Id: Ic94055a3f0d00f89354177de18bc27d2f4cecec2
Reviewed-on: http://gerrit.ent.cloudera.com:8080/2532
Reviewed-by: Ishaan Joshi <d1d1e60202ec9f2503deb1b724986485a125d802@cloudera.com>
Tested-by: jenkins
Reviewed-on: http://gerrit.ent.cloudera.com:8080/2594

  import logging
  import pytest
  from copy import copy
  from tests.common.test_vector import *
  from tests.common.impala_test_suite import *
  
  class TestDecimalQueries(ImpalaTestSuite):
    BATCH_SIZES = [0, 1]
  
    @classmethod
    def get_workload(cls):
      return 'functional-query'
  
    @classmethod
    def add_test_dimensions(cls):
      super(TestDecimalQueries, cls).add_test_dimensions()
      cls.TestMatrix.add_dimension(
          TestDimension('batch_size', *TestDecimalQueries.BATCH_SIZES))
  
      # On CDH4, hive does not support decimal so we can't run these tests against
      # the other file formats. Enable them on C5.
      cls.TestMatrix.add_constraint(lambda v:\
          (v.get_value('table_format').file_format == 'text' and
           v.get_value('table_format').compression_codec == 'none') or
           v.get_value('table_format').file_format == 'parquet')
  
    def test_queries(self, vector):
+     if os.environ.get('ASAN_OPTIONS') == 'handle_segv=0':
+       pytest.xfail(reason="IMPALA-959: Sum on a decimal column fails ASAN")
      new_vector = copy(vector)
      new_vector.get_value('exec_option')['batch_size'] = vector.get_value('batch_size')
      self.run_test_case('QueryTest/decimal', new_vector)
  
  
Fix the ASAN build by xfailing test_decimal when ASAN_OPTIONS is set.
## Code Before:
import logging
import pytest
from copy import copy
from tests.common.test_vector import *
from tests.common.impala_test_suite import *

class TestDecimalQueries(ImpalaTestSuite):
  BATCH_SIZES = [0, 1]

  @classmethod
  def get_workload(cls):
    return 'functional-query'

  @classmethod
  def add_test_dimensions(cls):
    super(TestDecimalQueries, cls).add_test_dimensions()
    cls.TestMatrix.add_dimension(
        TestDimension('batch_size', *TestDecimalQueries.BATCH_SIZES))

    # On CDH4, hive does not support decimal so we can't run these tests against
    # the other file formats. Enable them on C5.
    cls.TestMatrix.add_constraint(lambda v:\
        (v.get_value('table_format').file_format == 'text' and
         v.get_value('table_format').compression_codec == 'none') or
         v.get_value('table_format').file_format == 'parquet')

  def test_queries(self, vector):
    new_vector = copy(vector)
    new_vector.get_value('exec_option')['batch_size'] = vector.get_value('batch_size')
    self.run_test_case('QueryTest/decimal', new_vector)


## Instruction:
Fix the ASAN build by xfailing test_decimal when ASAN_OPTIONS is set.
## Code After:
import logging
import pytest
from copy import copy
from tests.common.test_vector import *
from tests.common.impala_test_suite import *

class TestDecimalQueries(ImpalaTestSuite):
  BATCH_SIZES = [0, 1]

  @classmethod
  def get_workload(cls):
    return 'functional-query'

  @classmethod
  def add_test_dimensions(cls):
    super(TestDecimalQueries, cls).add_test_dimensions()
    cls.TestMatrix.add_dimension(
        TestDimension('batch_size', *TestDecimalQueries.BATCH_SIZES))

    # On CDH4, hive does not support decimal so we can't run these tests against
    # the other file formats. Enable them on C5.
    cls.TestMatrix.add_constraint(lambda v:\
        (v.get_value('table_format').file_format == 'text' and
         v.get_value('table_format').compression_codec == 'none') or
         v.get_value('table_format').file_format == 'parquet')

  def test_queries(self, vector):
    if os.environ.get('ASAN_OPTIONS') == 'handle_segv=0':
      pytest.xfail(reason="IMPALA-959: Sum on a decimal column fails ASAN")
    new_vector = copy(vector)
    new_vector.get_value('exec_option')['batch_size'] = vector.get_value('batch_size')
    self.run_test_case('QueryTest/decimal', new_vector)

