Column name not found

我只是一个虾纸丫 提交于 2020-01-25 06:43:09

问题


I ran new query to overwrite a set of existing tables. The table schema changed as one of the expected results. So, as of the schema, one new column was added and two others were deleted. Suppose the one column added is named A

After a couple of minutes, when I query :

select A
from 'table_*'
WHERE _TABLE_SUFFIX = '20170831'

I had error: Name A not found

But this query just worked:

select A
from 'table_20170831'

Just wondering why. Because I really need to query for a longer period of time by using _TABLE_SUFFIX.....


回答1:


Just wondering why

The reason why you are getting this error is because the schema is being identified by earliest available sharded table - so in your case it means that in earliest table (table_*) there is/was no field named A

To workaround this - I would recommend creating dummy table with lowest date and with schema that consists all fields that you plan to query




回答2:


It's because the * matches a table that doesn't contain the newly added columns, and the schema of the wildcard table comes from the "latest" table based on its creation time. For example, you may have:

  • table_20170831: contains two new columns
  • table_foo: does not contain two new columns

In this case the * will match the second table. To fix this, use a longer prefix, such as:

SELECT *
FROM `table_2017*`
WHERE _TABLE_SUFFIX >= '0831';

For more reading, refer to the documentation on the schema used for evaluation of wildcard tables.



来源:https://stackoverflow.com/questions/46061964/column-name-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!