Repository: dbt-labs/dbt-core

Issue:
Agate type inference is too clever
### Describe the bug
We’re trying to set a value from a {% call statement %} and within the call, one line is SELECT 0 AS my_value...and it then treats it as a boolean (false) in the returned values. 

The same happens if we try SELECT 1 AS my_value, but as soon as we do SELECT 2 AS my_value it treats it like a number (as it should).

### Steps To Reproduce
Create a call statement that selects 0, or 1. false, and true respectively will be returned.

### Expected behavior
0, or 1 to be returned, as integers.

### Screenshots and log output

### System information
**Which database are you using dbt with?**
- [ ] postgres
- [ ] redshift
- [x] bigquery
- [ ] snowflake
- [ ] other (specify: ____________)


**The output of `dbt --version`:**
```
installed version: 0.15.0-a1
  latest version: 0.14.2
Your version of dbt is ahead of the latest release!
```

FYI, we run a fork, but that shouldn't have affected anything here.

**The operating system you're using:**

Mojave

**The output of `python --version`:**

Python 3.7.1

### Additional context
We'd love a quick fix for this, even if it's ugly!



Discussion:
[This line](https://github.com/fishtown-analytics/dbt/blob/2815b33b0ae1bc2c08650213b01338a0a669050e/core/dbt/clients/agate_helper.py#L49]) should have a `column_types=DEFAULT_TYPE_TESTER` parameter, just like line 32 above it.

Resolving patch:
diff --git a/core/dbt/clients/agate_helper.py b/core/dbt/clients/agate_helper.py
--- a/core/dbt/clients/agate_helper.py
+++ b/core/dbt/clients/agate_helper.py
@@ -46,7 +46,7 @@ def table_from_data_flat(data, column_names):
                 row.append(value)
         rows.append(row)
 
-    return agate.Table(rows, column_names)
+    return agate.Table(rows, column_names, column_types=DEFAULT_TYPE_TESTER)
 
 
 def empty_table():


Test patch:
diff --git a/test/integration/022_bigquery_test/macros/test_int_inference.sql b/test/integration/022_bigquery_test/macros/test_int_inference.sql
new file mode 100644
--- /dev/null
+++ b/test/integration/022_bigquery_test/macros/test_int_inference.sql
@@ -0,0 +1,13 @@
+
+{% macro test_int_inference() %}
+
+    {% set sql %}
+        select
+            0 as int_0,
+            1 as int_1,
+            2 as int_2
+    {% endset %}
+
+    {% do return(run_query(sql)) %}
+
+{% endmacro %}
diff --git a/test/integration/022_bigquery_test/test_bigquery_query_results.py b/test/integration/022_bigquery_test/test_bigquery_query_results.py
new file mode 100644
--- /dev/null
+++ b/test/integration/022_bigquery_test/test_bigquery_query_results.py
@@ -0,0 +1,39 @@
+from test.integration.base import DBTIntegrationTest, use_profile
+import json
+
+class TestBaseBigQueryResults(DBTIntegrationTest):
+
+    @property
+    def schema(self):
+        return "bigquery_test_022"
+
+    @property
+    def models(self):
+        return "models"
+
+    @property
+    def project_config(self):
+        return {
+            'macro-paths': ['macros'],
+        }
+
+    @use_profile('bigquery')
+    def test__bigquery_type_inference(self):
+        _, test_results = self.run_dbt(['run-operation', 'test_int_inference'])
+        self.assertEqual(len(test_results), 1)
+
+        actual_0 = test_results.rows[0]['int_0']
+        actual_1 = test_results.rows[0]['int_1']
+        actual_2 = test_results.rows[0]['int_2']
+
+        self.assertEqual(actual_0, 0)
+        self.assertEqual(str(actual_0), '0')
+        self.assertEqual(actual_0 * 2, 0) #  not 00
+
+        self.assertEqual(actual_1, 1)
+        self.assertEqual(str(actual_1), '1')
+        self.assertEqual(actual_1 * 2, 2) # not 11
+
+        self.assertEqual(actual_2, 2)
+        self.assertEqual(str(actual_2), '2')
+        self.assertEqual(actual_2 * 2, 4) # not 22