Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.facebook.presto.util;
import static com.facebook.presto.spi.type.VarcharType.VARCHAR;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
    @Test
    public void testExtraction()
            throws Exception
    {
        DelimitedRecordSet recordIterable = new DelimitedRecordSet(
                CharSource.wrap("apple,fuu,123\nbanana,bar,456"),
                Splitter.on(','),
                new ColumnMetadata("fruit", 0, false),
                new ColumnMetadata("foo", 1, false),
                new ColumnMetadata("value", 2, false));
        RecordCursor cursor = recordIterable.cursor();
        assertTrue(cursor.advanceNextPosition());
        assertEquals(cursor.getSlice(0), Slices.utf8Slice("apple"));
        assertEquals(cursor.getSlice(1), Slices.utf8Slice("fuu"));
        assertEquals(cursor.getSlice(2), Slices.utf8Slice("123"));
        assertEquals(cursor.getLong(2), 123L);
        assertEquals(cursor.getDouble(2), 123.0);
        assertTrue(cursor.advanceNextPosition());
        assertEquals(cursor.getSlice(0), Slices.utf8Slice("banana"));
        assertEquals(cursor.getSlice(1), Slices.utf8Slice("bar"));
        assertEquals(cursor.getSlice(2), Slices.utf8Slice("456"));
        assertEquals(cursor.getLong(2), 456L);
        assertEquals(cursor.getDouble(2), 456.0);
        assertFalse(cursor.advanceNextPosition());
    }
New to GrepCode? Check out our FAQ X