ilovesoup / asterixdb

Automatically exported from code.google.com/p/asterixdb
0 stars 0 forks source link

create-circle query outputting null when one of the variables shouldn't exist #836

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
DDL:
drop dataverse channels if exists;
create dataverse channels;
use dataverse channels;

//subscriptions
create type TweetHistorySubscription as open{
    subscription-id: int32,
    location: point,
    word: string
}

create dataset TweetHistorySubscriptions(TweetHistorySubscription)
primary key subscription-id;

create index testa on TweetHistorySubscriptions(location) type rtree;
create index testb on TweetHistorySubscriptions(word) type keyword;

create type TwitterUserType as open {
    screen-name: string,
    lang: string,
    friends-count: int32,
    statuses-count: int32,
    name: string,
    followers-count: int32
}

create type TweetMessageType as closed {
    tweetid: int64,
    user: TwitterUserType,
    sender-location: point,
    send-time: datetime,
    referred-topics: {{ string }},
    message-text: string,
    countA: int32,
    countB: int32
}

create dataset TweetMessages(TweetMessageType)
primary key tweetid;

create index locationIdx on TweetMessages(sender-location) type rtree;

load dataset TweetMessages using 
localfs(("path"="nc1://data/twitter/tw_for_indexleftouterjoin.adm"),("format"="a
dm"));

//All different subscriptions
insert into dataset TweetHistorySubscriptions(
[{"subscription-id":1,"location":point("0,0"),"word":"sprint"},
{"subscription-id":420,"location":point("70,70"),"word":"mind-blowing"}]
);

create function NearbyTweetsContainingText($location, $text) {
  for $tweet in dataset twitter.TweetMessageuuids
    let $circle := create-circle($location,30.0)
    where contains($tweet.message-text,$text)
    and spatial-intersect($tweet.location, $circle)
    return $tweet.message-text 
};

for $sub in dataset TweetHistorySubscriptions
let $circle := create-circle($location,30.0)
return {
"subscription-id":$sub.subscription-id,
"changeSet":1,
"execution-time":current-datetime(),
"message-text":"hello"
}

The last query outputs null.
The variable $location shouldn't exist in the last query. It seems to be 
related to the fact that the created function uses a variable with the same 
name (The error message displays correctly when the function is removed)

Original issue reported on code.google.com by sjaco...@ucr.edu on 6 Dec 2014 at 12:49

GoogleCodeExporter commented 9 years ago
I think this error originates in the initial Logical Plan creation which is 
(Before any optimizations):

distribute result [%0->$$8] -- |UNPARTITIONED|
  project ([$$8]) -- |UNPARTITIONED|
    assign [$$8] <- [function-call: asterix:open-record-constructor, Args:[AString: {subscription-id}, function-call: asterix:field-access-by-name, Args:[%0->$$4, AString: {subscription-id}], AString: {changeSet}, AInt32: {1}, AString: {execution-time}, function-call: asterix:current-datetime, Args:[], AString: {message-text}, AString: {hello}]] -- |UNPARTITIONED|
      assign [$$5] <- [function-call: asterix:create-circle, Args:[%0->null, ADouble: {30.0}]] -- |UNPARTITIONED|
        unnest $$4 <- function-call: asterix:dataset, Args:[AString: {TweetHistorySubscriptions}] -- |UNPARTITIONED|
          empty-tuple-source -- |UNPARTITIONED|

The "create-circle" function managed to get created with a "null" :
create-circle, Args:[%0->null, ADouble: {30.0}]

Original comment by sjaco...@ucr.edu on 8 Dec 2014 at 10:46

GoogleCodeExporter commented 9 years ago
Simpler Producing case:
drop dataverse channels if exists;
create dataverse channels;
use dataverse channels;

create type TweetHistorySubscription as open{
    subscription-id: int32
}

create dataset TweetHistorySubscriptions(TweetHistorySubscription)
primary key subscription-id;

create function NearbyTweetsContainingText($location) {
  for $tweet in dataset TweetHistorySubscription
    return $tweet
};

for $sub in dataset TweetHistorySubscriptions
return {
"message-text":$location
}

This seems to be an issue with scope. It looks like a function's "scope" 
becomes the parent "scope" of the following statement. Since the parent "scope" 
of the FLWOR has the symbol "location" it is assumed to exist.

Original comment by sjaco...@ucr.edu on 10 Dec 2014 at 7:35

GoogleCodeExporter commented 9 years ago

Original comment by sjaco...@ucr.edu on 15 Dec 2014 at 7:05

GoogleCodeExporter commented 9 years ago

Original comment by sjaco...@ucr.edu on 16 Dec 2014 at 9:45

GoogleCodeExporter commented 9 years ago

Original comment by sjaco...@ucr.edu on 29 Dec 2014 at 5:43