我无法查询 GQL,只能使用通配符来查询所有属性。

huangapple go评论82阅读模式
英文:

I can't query GQL for 2 properties only wildcard is working

问题

我在Datastore中存储了comment实体,并使用Datastore Viewer查看存储的数据。

我可以执行以下查询:

select * from comment    
select __key__ from comment
select Subject from comment
select Comment from comment

但是我无法执行以下查询:

select Subject, Comment from comment
// 错误:此查询的建议索引为:
//    - kind: comment
//      properties:
//      - name: Comment
//      - name: Subject
select __key__, Subject, Comment from comment
// 错误:不支持对属性 __key__ 进行投影

我找不到任何关于为什么出错的参考。这些错误信息并没有告诉我太多信息。

我没有为这些实体设置任何键或索引。

文档中提到了以下内容:

SELECT [DISTINCT] [* | <property list> | __key__]
  [FROM <kind>]
  [WHERE <condition> [AND <condition> ...]]
  [ORDER BY <property> [ASC | DESC] [, <property> [ASC | DESC] ...]]
  [LIMIT [<offset>,]<count>]
  [OFFSET <offset>]

  <property list> := <property> [, <property> ...]
  <condition> := <property> {< | <= | > | >= | = | != } <value>
  <condition> := <property> IN <list>
  <condition> := ANCESTOR IS <entity or key>
  <list> := (<value> [, <value> ...]])

Subject, Comment 是属性列表,是一个有效的查询。但实际上却不是。
我是用Go代码创建的实体。

英文:

I store comment entity in Datastore and I use Datastore Viewer to see stored data.

I can do following queries

select * from comment    
select __key__ from comment
select Subject from comment
select Comment from comment

But I can't query

select Subject, Comment from comment
// Error: The suggested index for this query is:
//    - kind: comment
//      properties:
//      - name: Comment
//      - name: Subject
select __key__, Subject, Comment from comment
// Error: projections are not supported for the property: __key__

I can't find any reference why it is wrong. These errors does not tell me much.

I have not set any key or index for these entities.

Documentation tells following:

SELECT [DISTINCT] [* | &lt;property list&gt; | __key__]
  [FROM &lt;kind&gt;]
  [WHERE &lt;condition&gt; [AND &lt;condition&gt; ...]]
  [ORDER BY &lt;property&gt; [ASC | DESC] [, &lt;property&gt; [ASC | DESC] ...]]
  [LIMIT [&lt;offset&gt;,]&lt;count&gt;]
  [OFFSET &lt;offset&gt;]

  &lt;property list&gt; := &lt;property&gt; [, &lt;property&gt; ...]
  &lt;condition&gt; := &lt;property&gt; {&lt; | &lt;= | &gt; | &gt;= | = | != } &lt;value&gt;
  &lt;condition&gt; := &lt;property&gt; IN &lt;list&gt;
  &lt;condition&gt; := ANCESTOR IS &lt;entity or key&gt;
  &lt;list&gt; := (&lt;value&gt; [, &lt;value&gt; ...]])

Subject, Comment - is property list and it valid query. But it is not.
I created entity from Go code.

答案1

得分: 3

投影查询有一些限制。在projection-doc中提到了"只有索引属性可以进行投影"

第一个错误消息明确显示了Subject, Comment的组合索引尚不存在。您可以通过在项目根文件夹的index.yaml中添加以下内容来手动创建索引:

- kind: comment
  properties:
  - name: Comment
  - name: Subject

请参考index spec和projection-doc。

// 错误:不支持对属性进行投影:key

keys实体是通过GetAll方法返回的。不要将它们放在投影中。

keys, err := q.GetAll(c, &people)

我还不能发布超过2个链接,所以请在数据存储参考中查找更多详细信息。

英文:

The projection queries come with some limitations. In the projection-doc is mentioned that &quot;Only indexed properties can be projected&quot;.

The first error message shows exactly that the combined index of Subject, Comment doesn't exist yet. You can create the index manually by adding

- kind: comment
  properties:
  - name: Comment
  - name: Subject

to your index.yaml in your project root folder. Please have a look at the index spec and projection-doc.

// Error: projections are not supported for the property: __key__

Entity keys are returned by the GetAll method. Don't put them in your projection.

keys, err := q.GetAll(c, &amp;people)

I can't post more than 2 links yet, so please look for more details in the datastore reference.

huangapple
  • 本文由 发表于 2014年1月9日 19:35:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/21019092.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定