From c779384bc5fb16b31baab06c51855c46250240bf Mon Sep 17 00:00:00 2001 From: Daniel Grazian Date: Fri, 8 Sep 2017 14:45:46 -0700 Subject: [PATCH] Added code example to the doc string for `SqlDataset`. PiperOrigin-RevId: 168049037 --- .../contrib/data/python/ops/dataset_ops.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tensorflow/contrib/data/python/ops/dataset_ops.py b/tensorflow/contrib/data/python/ops/dataset_ops.py index 0ee9acfc97f..cfacfdd7d99 100644 --- a/tensorflow/contrib/data/python/ops/dataset_ops.py +++ b/tensorflow/contrib/data/python/ops/dataset_ops.py @@ -2276,6 +2276,23 @@ class SqlDataset(Dataset): def __init__(self, driver_name, data_source_name, query, output_types): """Creates a `SqlDataset`. + `SqlDataset` allows a user to read data from the result set of a SQL query. + For example: + + ```python + dataset = tf.contrib.data.SqlDataset("sqlite", "/foo/bar.sqlite3", + "SELECT name, age FROM people", + (tf.string, tf.int32)) + iterator = dataset.make_one_shot_iterator() + next_element = iterator.get_next() + # Prints the rows of the result set of the above query. + while True: + try: + print(sess.run(next_element)) + except tf.errors.OutOfRangeError: + break + ``` + Args: driver_name: A 0-D `tf.string` tensor containing the database type. Currently, the only supported value is 'sqlite'.