lwhay / asterixdb

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

Able to pass a String to a created function that expects a Point #835

Open GoogleCodeExporter opened 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 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;

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 TweetMessages
    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
for $text in NearbyTweetsContainingText($sub.word,$sub.word)
return $text;

This query should fail, since $sub.word is a String rather than a Point. But it 
runs and actually returns results.

Original issue reported on code.google.com by sjaco...@ucr.edu on 5 Dec 2014 at 9:05

GoogleCodeExporter commented 9 years ago
All of the functions that take spatial types should probably be inspected - it 
may be that none of them are protecting themselves...

Original comment by dtab...@gmail.com on 6 Dec 2014 at 1:48

GoogleCodeExporter commented 9 years ago
Actually CreateCircleDescriptor has the following protection. I am not sure why 
this is not triggered.

                        // Type check: (point, double)
                        if (outInput0.getByteArray()[0] != SER_POINT_TYPE_TAG
                                || outInput1.getByteArray()[0] != SER_DOUBLE_TYPE_TAG) {
                            throw new AlgebricksException(AsterixBuiltinFunctions.CREATE_CIRCLE.getName()
                                    + ": expects input type (POINT, DOUBLE) but got ("
                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(outInput0.getByteArray()[0])
                                    + ", "
                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(outInput1.getByteArray()[0])
                                    + ")");
                        }

Original comment by wangs...@gmail.com on 6 Dec 2014 at 1:57

GoogleCodeExporter commented 9 years ago
Yeah actually in most cases it does throw a message saying that the type is 
wrong. I had to work hard to produce this bug. It seems to correlate with using 
it in a "for" statement.

Original comment by sjaco...@ucr.edu on 6 Dec 2014 at 3:18

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
During the optimization, suddenly, all operators inside the function is gone. 
If you check the final plan, it's so simple. And, the debugging tells me that 
it does not go through "createCircleDescriptor". So, I think the problem exists 
in the "edu.uci.ics.asterix.optimizer.rules.CancelUnnestWithNestedListifyRule" 
rule. 

Dec 05, 2014 7:29:03 PM 
edu.uci.ics.hyracks.algebricks.core.rewriter.base.AbstractRuleController 
printRuleApplication
FINE: >>>> Rule class 
edu.uci.ics.asterix.optimizer.rules.CancelUnnestWithNestedListifyRule fired.

Dec 05, 2014 7:29:03 PM 
edu.uci.ics.hyracks.algebricks.core.rewriter.base.AbstractRuleController 
printRuleApplication
FINE: >>>> Before plan
distribute result [%0->$$1] -- |UNPARTITIONED|
  project ([$$1]) -- |UNPARTITIONED|
    unnest $$1 <- function-call: asterix:scan-collection, Args:[%0->$$17] -- |UNPARTITIONED|
      group by ([$$18 := %0->$$23]) decor ([%0->$$0; %0->$$2]) {
                aggregate [$$17] <- [function-call: asterix:listify, Args:[%0->$$20]] -- |UNPARTITIONED|
                  select (function-call: asterix:spatial-intersect, Args:[%0->$$21, %0->$$5]) -- |UNPARTITIONED|
                    assign [$$5] <- [function-call: asterix:create-circle, Args:[%0->$$2, ADouble: {30.0}]] -- |UNPARTITIONED|
                      assign [$$21] <- [function-call: asterix:field-access-by-name, Args:[%0->$$4, AString: {location}]] -- |UNPARTITIONED|
                        select (function-call: algebricks:not, Args:[function-call: algebricks:is-null, Args:[%0->$$22]]) -- |UNPARTITIONED|
                          nested tuple source -- |UNPARTITIONED|
             } -- |UNPARTITIONED|
        left outer join (function-call: asterix:contains, Args:[%0->$$20, %0->$$2]) -- |UNPARTITIONED|
          assign [$$2] <- [function-call: asterix:field-access-by-index, Args:[%0->$$0, AInt32: {2}]] -- |UNPARTITIONED|
            data-scan []<-[$$23, $$0] <- channels:TweetHistorySubscriptions -- |UNPARTITIONED|
              empty-tuple-source -- |UNPARTITIONED|
          assign [$$22] <- [TRUE] -- |UNPARTITIONED|
            assign [$$20] <- [function-call: asterix:field-access-by-index, Args:[%0->$$4, AInt32: {5}]] -- |UNPARTITIONED|
              data-scan []<-[$$19, $$4] <- channels:TweetMessages -- |UNPARTITIONED|
                empty-tuple-source -- |UNPARTITIONED|

Dec 05, 2014 7:29:03 PM 
edu.uci.ics.hyracks.algebricks.core.rewriter.base.AbstractRuleController 
printRuleApplication
FINE: >>>> After plan
distribute result [%0->$$1] -- |UNPARTITIONED|
  project ([$$1]) -- |UNPARTITIONED|
    assign [$$1] <- [%0->$$20] -- |UNPARTITIONED|
      order (ASC, %0->$$23)  -- |UNPARTITIONED|
        assign [$$18] <- [%0->$$23] -- |UNPARTITIONED|
          left outer join (function-call: asterix:contains, Args:[%0->$$20, %0->$$2]) -- |UNPARTITIONED|
            assign [$$2] <- [function-call: asterix:field-access-by-index, Args:[%0->$$0, AInt32: {2}]] -- |UNPARTITIONED|
              data-scan []<-[$$23, $$0] <- channels:TweetHistorySubscriptions -- |UNPARTITIONED|
                empty-tuple-source -- |UNPARTITIONED|
            assign [$$22] <- [TRUE] -- |UNPARTITIONED|
              assign [$$20] <- [function-call: asterix:field-access-by-index, Args:[%0->$$4, AInt32: {5}]] -- |UNPARTITIONED|
                data-scan []<-[$$19, $$4] <- channels:TweetMessages -- |UNPARTITIONED|
                  empty-tuple-source -- |UNPARTITIONED|

Original comment by wangs...@gmail.com on 6 Dec 2014 at 3:39

GoogleCodeExporter commented 9 years ago

Original comment by sjaco...@ucr.edu on 15 Dec 2014 at 6:54

GoogleCodeExporter commented 9 years ago
Wierd! Once the problem is fixed, then, I guess this won't happen - too bad 
since I was going to suggest an error message like "AsterixDB doesn't accept 
pointless calls to this function." :-)

Original comment by dtab...@gmail.com on 16 Dec 2014 at 6:43