// ============================================================================
//
// Copyright (C) 2006-2016 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.components.common.dataset.runtime;

import org.apache.avro.Schema;
import org.apache.avro.generic.IndexedRecord;
import org.talend.components.api.component.runtime.RuntimableRuntime;
import org.talend.components.common.dataset.DatasetProperties;
import org.talend.daikon.properties.Properties;

/**
 * Provides access to runtime methods on a dataset.
 *
 * The runtime objects are created by via a
 * {@link org.talend.components.common.dataset.DatasetDefinition#getRuntimeInfo(Properties, Object)}, where the
 * properties contain all of the configuration necessary to access the dataset.
 * 
 * @param <DatasetPropT> The properties that specify a dataset.
 */
public interface DatasetRuntime<DatasetPropT extends DatasetProperties> extends RuntimableRuntime<DatasetPropT> {

    /** @return a Schema for the dataset. */
    Schema getSchema();

    /**
     * Discover a sample of data from the dataset.
     *
     * There is no requirement for sort order or start position, unless specified in the dataset properties.
     *
     * @param limit the maximum number of records to return.
     * @return a list of IndexedRecords that the dataset can support.
     */
    Iterable<? extends IndexedRecord> getSample(int limit);
}

@@ -781,16 +781,57 @@
 erties;%0A
+import org.talend.daikon.java8.Consumer;%0A
 import o
@@ -1678,76 +1678,225 @@
  * @
-return a list of IndexedRecords that the dataset can support
+param consumer a callback that will be applied to each sampled record. This callback should throw a%0A     * %7B@link org.talend.daikon.exception.TalendRuntimeException%7D if there was an error processing the record
 .%0A     *
 /%0A  
@@ -1895,67 +1895,242 @@
    *
-/%0A    Iterable%3C? extends IndexedRecord%3E getSample(int limit
+ @throws org.talend.daikon.exception.TalendRuntimeException propagated from the callback, if any, or if there was%0A     * a runtime exception generating the sample.%0A     */%0A    void getSample(int limit, Consumer%3CIndexedRecord%3E consumer
 );%0A%7D

change DatasetRuntime getSample method to enable stream… (#344)