When Sora first realizes he is on the beach, he sees Riku standing in shallow water, looking out to the horizon. Before he can call out to him, Sora sees the water receding, and a wave forming in front of Riku. Riku senses that Sora is there, so he tilts his head down and to the side, pauses briefly, then proceeds to turn around and face him. He extends his hand towards Sora, as if asking him to go with him. Sora is more concerned with the wave that is about to fall on Riku, and immediately begins running towards him. He reaches out to him, but Riku disappears. Sora is now tumbling underwater. When he looks up he sees Riku "standing" there looking back at him. Riku holds out his hand once more, and Sora struggles to fight against the torrents so he can reach him, but he ends up flowing back with them.
Now let's take a deeper look. The events that occur in Sora's dream parallel those that occur later in the game. First off, we know that Riku wants to travel to other worlds out there, and he constantly looks out to the horizon for that reason. When the Destiny Islands world is flooded with heartless, Sora is wary of leaving, but Riku wants to go. He says is not afraid of the darkness, and asks Sora to come with him. This relates to the part in Sora's dream when Riku first extends his hand. Sora goes after him, meaning he travels out to the other worlds. Riku's disappearance in the dream signifies his separation from Sora. Both have no idea where the other is.
Sora's underwater tumble represents his journey through the other worlds. Riku's presence signifies that the two have encountered each other in a few of those worlds. Again, Riku asks Sora to join him, and although Sora wants to get his friend back, the torrent, representing light, prevents him from doing so. Riku is in the hands of evil, and Sora realizes that, so the water pushes him away until Riku is no longer in his sight.